有关于String常用的方法
subString(int beginIndex)
这个方法的根本就是截取字符串
if (beginIndex < 0) {
throw new StringIndexOutOfBoundsException(beginIndex);
}
int subLen = value.length - beginIndex;
if (subLen < 0) {
throw new StringIndexOutOfBoundsException(subLen);
}
return (beginIndex == 0) ? this : new String(value, beginIndex, subLen);
上面是它的核心字符串,如果index符合正常就使用String的构造函数返回出需要的字符串。
public String(char chars[], int x, int n);
这个是String的构造函数俗话说字符数组与String不分家。
public boolean equals(Object anObject) {}
这个方法判断字符串内容是否相等。
public String trim() {}
这个方法作用就是出去两端的空格不包括中间的空格。
public String replaceAll(String regex, String replacement) {}
此方法用于替换String中所有的regex为replacement。
public int lastIndexOf(int ch){}
此方法就是获取最后一个char的位置
有关于StringUtils,这个提供了大量的处理String的方法
可以直接获取最后一个小数点后的数据
public static String substringBeforeLast(String str, String separator) {
if (!isEmpty(str) && !isEmpty(separator)) {
int pos = str.lastIndexOf(separator);
return pos == -1 ? str : str.substring(0, pos);
} else {
return str;
}
}
这个方法其实就是调用了String获取最后一个小数点的方法。
StringUtils.substringBeforeLast("adfa.aasf.","");