Module1:
package com.string.exer;
public class StringMethodTest {
public static void main(String[] args) {
String str = "Hello Big Data";
int len = str.length();
System.out.println(len);
char c = str.charAt(0);
System.out.println(c);
System.out.println(str.isEmpty());
String str2 = str.toUpperCase();
System.out.println(str2);
System.out.println(str);
String str3 = str.toLowerCase();
System.out.println(str3);
String str4 = " hello az ";
System.out.println("------" + str4.trim() + "------");
}
}
Module2:
package com.string.exer;
public class StringMethodTest2 {
public static void main(String[] args) {
String s1 = "hello";
String s2 = "hello";
System.out.println(s1.equals(s2));
String s3 = "Hello";
String s4 = "hello";
System.out.println(s3.equals(s4));
System.out.println(s3.equalsIgnoreCase(s4));
String s5 = "aaa";
String s6 = s5.concat("bbb");
System.out.println(s6);
String s7 = "aaa";
String s8 = "bbb";
System.out.println(s7.compareTo(s8));
String s9 = "你好啊南工";
System.out.println(s9.substring(2));
System.out.println(s9.substring(3, 5));
}
}
Module3:
package com.string.exer;
import org.junit.jupiter.api.Test;
public class StringMethodTest3 {
@Test
public void test3() {
String s1 = "helloworld";
boolean b1 = s1.endsWith("rld");
System.out.println(b1);
boolean b2 = s1.startsWith("hell");
System.out.println(b2);
boolean b3 = s1.startsWith("ll", 2);
System.out.println(b3);
boolean b4 = s1.contains("orl");
System.out.println(b4);
int t1 = s1.indexOf("ll");
System.out.println(t1);
int t2 = s1.indexOf("ll", 4);
System.out.println(t2);
String s2 = "hellorworld";
int t3 = s2.lastIndexOf("or");
System.out.println(t3);
int t4 = s2.lastIndexOf("or", 6);
System.out.println(t4);
}
@Test
public void test2() {
String s1 = "你好南工,南工你好";
String s2 = s1.replace("南", "东");
System.out.println(s2);
String s3 = "abcdbf";
String s4 = s3.replace("bc", "nn");
System.out.println(s4);
String str5 = "12hello34world5java7891mysql456";
String string = str5.replaceAll("\\d+", ",").replaceAll("^,|,$", "");
System.out.println(string);
String str = "12345";
boolean matches = str.matches("\\d+");
System.out.println(matches);
String tel = "0571-4534289";
boolean result = tel.matches("0571-\\d{7,8}");
System.out.println(result);
String s5 = "hello|world|java";
String[] strs = s5.split("\\|");
for(String s : strs) {
System.out.print(s + " ");
}
}
public static void main(String[] args) {
}
}