多个字符分割 比如我想把有,或者有分号的都分开
Pattern pattern = Pattern.compile("[,;]+");
String[] strs = pattern.split("Java Hello World Java,Hello,,World;Sun");
for (int i=0;i<strs.length;i++) {
System.out.println(strs[i]);
}
取文本中多个数值的较大值
protected String formatMaxNumber(String value) {
List<Float> fl = new ArrayList<Float>();
if (value != null) {
Matcher valueMatcher = intPattern.matcher(value);
while (valueMatcher.find()) {
String strRjl = valueMatcher.group();
float rst = Float.valueOf(strRjl);
fl.add(rst);
}
if (fl.size() == 1) {
return fl.get(0).toString();
} else if (fl.size() == 2) {
if (fl.get(0) > fl.get(1)) {
return fl.get(0).toString();
} else {
return fl.get(1).toString();
}
}
}
return null;
} |