标签:
赋值 .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()转换为大写
标签:
原文地址:http://www.cnblogs.com/xiaolei121/p/5725763.html