String方法

时间:2023-01-07 13:16:09

判断是否相等:

        String a = "令狐冲";
String b = "令狐";
String c = "冲";
String d = new String("令狐冲");
String e = b + c; System.out.println(a == (b + c));
System.out.println(a == d);
System.out.println(e == (b + c)); d.intern();
System.out.println(a == d);
d = d.intern();
System.out.println(a == d);

String方法

String 大小写转换:

String str = "ABC";
String str1 = "abc"; System.out.println("ABC大写转小写: " + str.toLowerCase());
System.out.println("abc小写转大写: " + str1.toUpperCase());