@Test public void test1 (){ String s1 = "Hello World"; System.out.println(s1.length()); //0-(s1.length()-1) System.out.println(s1.charAt(5)); //判空 System.out.println(s1.isEmpty()); //转大转小 String s2 =s1.toUpperCase(Locale.ROOT); String s3 =s1.toLowerCase(Locale.ROOT); System.out.println(s2); System.out.println(s3); //字符串匹配 System.out.println(s2.equals(s3)); //忽略大小写字符串匹配 System.out.println(s2.equalsIgnoreCase(s3)); // String s4 = "123"+s2.concat(s1)+s2.concat("zhou"); System.out.println(s4); //比较字符串大小 String s5 = "154"; String s6 = "158"; String s7 = "dadada"; //比较的逻辑,没搞懂(涉及到字符串排序) System.out.println(s5.compareTo(s6));//-4 System.out.println(s5.compareTo(s7));//-51 //截取部分字符串 System.out.println(s1.substring(2)); System.out.println(s1.substring(2, 5)); }
结果
11 false HELLO WORLD hello world false true 123HELLO WORLDHello WorldHELLO WORLDzhou -4 -51 llo World llo
代码
public void test2(){ String s1 = "Hello World"; boolean b1 =s1.endsWith("d"); boolean b2 =s1.endsWith("World"); System.out.println(b1); System.out.println(b2); boolean b3 = s1.startsWith("H"); System.out.println(b3); System.out.println(s1.startsWith("h")); System.out.println(s1.contains("lo")); }
结果
public void test2(){ String s1 = "Hello World"; boolean b1 =s1.endsWith("d"); boolean b2 =s1.endsWith("World"); System.out.println(b1); System.out.println(b2); boolean b3 = s1.startsWith("H"); System.out.println(b3); System.out.println(s1.startsWith("h")); System.out.println(s1.contains("lo")); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)