String类型

 

 字符串类型变为基本类型
  例如:  String a="123";
int xx=Integer.parseInt(x);
基本数据类型转化包装类型
      例如:  int a=123;
    Integer a_new=Integer.valueOf(a);
字符串类型转化为包装类型
    
    例如:   String b = "123.0";
    Float b_new = Float.valueOf(b);
    System. out.println (b_new) ;
    

 

int aa= 3 ;
int bb= 4 ;
String aa_new =aa+""+bb;
//等价于String
//String aa_new = Integer.toString(aa) . concat (Integer.toString (bb)) ;
system.out.println (aa_new) ;
// 5.trim ()把字符串两边的空格去除String a = " hello world ";System.out.println (a.trim() );

//基本数据类型可以自动转换成包装类型(装箱)--->JDK1.5之后的特性系统自动装换
//包装类可以自动转换成基本数据类型(拆箱)
}
Integer a=5;
int b=a;
//基本数据类型比较内容只能使用"=="
int a = 3;
int b = 3;
System. out.println (a==b) ;
/字符串类型比较内容可以使用==,或者使用equals ()String c = "123";
String d = "123";
System. out.println (c.equals (d)) ;
//==和equals()的区别-—-->极其重要!!!!//字符串比较的方法:
l l equals()比较两个字符串的内容是否相同,
//==比较两个字符串内存地址是否相等,比较两个字符串是否为同一对象
}
//基本数据类型比较内容只能使用"=="
/字符串类型比较内容可以使用==,或者使用equals ()
//==和equals()的区别-—-->极其重要!!!!//字符串比较的方法:
l l equals()比较两个字符串的内容是否相同,
//==比较两个字符串内存地址是否相等,比较两个字符串是否为同一对象
//2 .toLowerCase()将字符串转换为小写
String a = "tom" ;
String b = "TOM" .toLowerCase ();
System. out.println (a.equals (b));
3.toUpperCase()将字符串转换成大写
String a = "tom" . toUpperCase () ;
String b ="TOM";
System. out.println (a.equals (b));题
// 4.contact()将两个字符串拼接
String a = "abc" ;
String b = "d" ;
system.out.println (a. concat(b)) ;
.equalsIgnoreCase()方法用于将字符串与指定的对象比较,不考虑大小写
String a = "tom" ;
String b = "TOM";
System .out.println(a.equalsIgnoreCase(b)) ;

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值