package com.atguigu.java; import org.junit.Test; /** * @author Suki * @creat 2022-09-16 19:10 */ public class StringMethodTest { @Test public void test2(){ String s1 = "HelloWorld"; String s2 = "helloworld"; System.out.println(s1.equals(s2)); System.out.println(s1.equalsIgnoreCase(s2)); String s3 = "abc"; String s4 = s3.concat("def");//连接 System.out.println(s4);//abcdef String s5 = "abc"; String s6 = new String("abe"); System.out.println(s5.compareTo(s6));//-2 涉及到字符串排序 String s7 = "abcdefg"; String s8 = s7.substring(2); System.out.println(s7);//abcdefg System.out.println(s8);//cdefg String s9 = s7.substring(2,5); System.out.println(s9);//cde [2,5)左开右闭 } @Test public void test1(){ String s1 = "HelloWorld"; System.out.println(s1.length());//10 System.out.println(s1.charAt(0));//h // System.out.println(s1.charAt(10));//角标越界 System.out.println(s1.isEmpty());//false--判断数组长度 String s2 = s1.toLowerCase(); System.out.println(s1);//HelloWorld s1不可变的 System.out.println(s2);//helloworld 改成小写以后的字符串 String s3 = " he l lo wor ld "; String s4 = s3.trim();//去除首位空格 System.out.println("-----" + s3 + "-----"); System.out.println("-----" + s4 + "-----"); } }