package cn.lgt.stringmethods;
public class StringOtherMethods {
public static void stringOtherMehtods(){
//String类的其他功能
//替换功能
//1. String replace(char old, char new);
//2. String replace(String old, String new);
String s1 = "helloworld";
System.out.println(s1.replace('o', 'm'));
System.out.println(s1.replace("world", "java"));
//去除字符串两端的空格
//String trim();
String s2 = " dd sss d ";
System.out.println(s2.trim());
//按照字典顺序比较两个字符串
//int compareTo(String str);//区分大小写
//int compareToIgnoreCase(String str);//不区分大小写
String s3 = "helloworld";
String s4 = "HELLOWORLD";
String s5 = "hello";
String s6 = "world";
System.out.println(s3.compareTo(s5));//前面都相同,返回相差的字符数
System.out.println(s3.compareToIgnoreCase(s4));//不区分大小写,相同,返回数值0
System.out.println(s3.compareTo(s6));
}
}