码迷,mamicode.com
首页 > 其他好文 > 详细

String类

时间:2016-08-01 15:22:01      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:

赋值    .length()方法只有字符串有

 

String s = new String();
s = "HelloWorld";
System.out.println(s.length());

String s1 = "Hello World";
System.out.println(s1.length());

String s2 = new String("Hello World");
System.out.println(s2.length());

.equals()方法

// == 比较地址 new 出新地址 S5 S6不等
String s3 = "123";
String s4 = "123";
System.out.println(s3 == s4);  //结果为true
String s5 = new String("1234");
String s6 = new String("1234");
System.out.println(s5 == s6);  //结果为false
// .equals() 比较内部内容
System.out.println(s5.equals(s6));  //结果为true
//.equalsIgnoreCase()  忽略大小写

String s7 = "tom";
String s8 = "Tom";
System.out.println(s7.equals(s8)); //false
System.out.println(s7.equalsIgnoreCase(s8)); //true .equalsIgnoreCase()大小写转换

String s70 = s7.toUpperCase();
String s80 = s8.toUpperCase();
System.out.println(s70.equals(s80));//true .toUpperCase()转换为大写

 

String类

标签:

原文地址:http://www.cnblogs.com/xiaolei121/p/5725763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!