目 录![](https://img-blog.csdnimg.cn/3c3163bb2a6949b8adbdbeaef4e2ae41.gif)
1.判断功能的方法
2.转换功能的方法
3.获取功能的方法
4.替换功能的方法
5.去除字符串两空格的方法
6.按字典顺序比较两个字符串
1.判断功能的方法
- public boolean equals(Object obj): 比较字符串的内容是否相同,区分大小写
- public boolean equalsIgnoreCase(String str): 比较字符串的内容是否相同,忽略大小写
- public boolean contains(String str): 判断字符串中是否包含传递进来的字符串
- public boolean startsWith(String str): 判断字符串是否以传递进来的字符串开头
- public boolean endsWith(String str): 判断字符串是否以传递进来的字符串结尾
- public boolean isEmpty(): 判断字符串的内容是否为空串
public class Test {
public static void main(String[] args) {
boolean b = "abc".equals("ABC"); //区分大小写
System.out.println(b); //false
System.out.println("abc".equalsIgnoreCase("ABC")); //不区分大小写 true
String s = "好好学习,天天向上";
boolean b1 = s.contains("好好学习");
System.out.println(b1); //true
String s3 = "王老虎";
System.out.println(s3.startsWith("王")); //true
System.out.println(s3.endsWith("老虎")); //true
System.out.println("".isEmpty()); //true
System.out.println("".length() == 0); //true
System.out.println(s3.isEmpty()); //false
}
}
2.转换功能的