数组辅助类Arrays
1. 数组和字符串相互比较
char[] chs={'c','a','r'};
String str = new String(chs);
char[] charArray=s.toCharArray();
2.大小写转换
.toUpperCase()
.toLowerCase()
3.去掉空格(第一个之前的空格,最后一个字符的空格)
.trim()
4.比较
.equals()
.equalsIgnore() //忽略大小写
5.子字符串位置
indexOf
lastIndexof
replace
6.分割字符串
.split(字符串)
正则表达式的基本操作:
-
编译正则表达式:
Pattern pattern = Pattern.compile("正则表达式");
-
创建 Matcher 对象:
Matcher matcher = pattern.matcher("要匹配的字符串");
-
查找匹配项:
boolean found = matcher.find();
-
替换匹配项
String result = matcher.replaceAll("替换文本");
-
检查输入是否完全匹配正则表达式:
boolean matches = matcher.matches();