publicintindexOf(int ch){returnindexOf(ch,0);}publicintindexOf(int ch,int fromIndex){finalint max = value.length;if(fromIndex <0){
fromIndex =0;}elseif(fromIndex >= max){// Note: fromIndex might be near -1>>>1.return-1;}if(ch <Character.MIN_SUPPLEMENTARY_CODE_POINT){// handle most cases here (ch is a BMP code point or a// negative value (invalid code point))finalchar[] value =this.value;for(int i = fromIndex; i < max; i++){if(value[i]== ch){return i;}}return-1;}else{returnindexOfSupplementary(ch, fromIndex);}}
publicStringtrim(){int len = value.length;int st =0;char[] val = value;/* avoid getfield opcode */while((st < len)&&(val[st]<=' ')){
st++;}while((st < len)&&(val[len -1]<=' ')){
len--;}return((st >0)||(len < value.length))?substring(st, len):this;}
5 split():分割字符串,返回一个分割后的字符串数组。
publicString[]split(String regex,int limit){/* fastpath if the regex is a
(1)one-char String and this character is not one of the
RegEx's meta characters ".$|()[{^?*+\\", or
(2)two-char String and the first char is the backslash and
the second is not the ascii digit or ascii letter.
*/char ch =0;if(((regex.value.length ==1&&".$|()[{^?*+\\".indexOf(ch = regex.charAt(0))==-1)||(regex.length()==2&&
regex.charAt(0)=='\\'&&(((ch = regex.charAt(1))-'0')|('9'-ch))<0&&((ch-'a')|('z'-ch))<0&&((ch-'A')|('Z'-ch))<0))&&(ch <Character.MIN_HIGH_SURROGATE ||
ch >Character.MAX_LOW_SURROGATE)){int off =0;int next =0;boolean limited = limit >0;ArrayList<String> list =newArrayList<>();while((next =indexOf(ch, off))!=-1){if(!limited || list.size()< limit -1){
list.add(substring(off, next));
off = next +1;}else{// last one//assert (list.size() == limit - 1);
list.add(substring(off, value.length));
off = value.length;break;}}// If no match was found, return thisif(off ==0)returnnewString[]{this};// Add remaining segmentif(!limited || list.size()< limit)
list.add(substring(off, value.length));// Construct resultint resultSize = list.size();if(limit ==0){while(resultSize >0&& list.get(resultSize -1).isEmpty()){
resultSize--;}}String[] result =newString[resultSize];return list.subList(0, resultSize).toArray(result);}returnPattern.compile(regex).split(this, limit);}
publicStringtoLowerCase(){returntoLowerCase(Locale.getDefault());}publicStringtoLowerCase(Locale locale){if(locale ==null){thrownewNullPointerException();}int firstUpper;finalint len = value.length;/* Now check if there are any characters that need to be changed. */
scan:{for(firstUpper =0; firstUpper < len;){char c = value[firstUpper];if((c >=Character.MIN_HIGH_SURROGATE)&&(c <=Character.MAX_HIGH_SURROGATE)){int supplChar =codePointAt(firstUpper);if(supplChar !=Character.toLowerCase(supplChar)){break scan;}
firstUpper +=Character.charCount(supplChar);}else{if(c !=Character.toLowerCase(c)){break scan;}
firstUpper++;}}returnthis;}
9 toUpperCase():将字符串转成大写字符。
publicStringtoUpperCase(){returntoUpperCase(Locale.getDefault());}publicStringtoUpperCase(Locale locale){if(locale ==null){thrownewNullPointerException();}int firstLower;finalint len = value.length;/* Now check if there are any characters that need to be changed. */
scan:{for(firstLower =0; firstLower < len;){int c =(int)value[firstLower];int srcCount;if((c >=Character.MIN_HIGH_SURROGATE)&&(c <=Character.MAX_HIGH_SURROGATE)){
c =codePointAt(firstLower);
srcCount =Character.charCount(c);}else{
srcCount =1;}int upperCaseChar =Character.toUpperCaseEx(c);if((upperCaseChar ==Character.ERROR)||(c != upperCaseChar)){break scan;}
firstLower += srcCount;}returnthis;}/* result may grow, so i+resultOffset is the write location in result */int resultOffset =0;char[] result =newchar[len];/* may grow *//* Just copy the first few upperCase characters. */System.arraycopy(value,0, result,0, firstLower);String lang = locale.getLanguage();boolean localeDependent =(lang =="tr"|| lang =="az"|| lang =="lt");char[] upperCharArray;int upperChar;int srcChar;int srcCount;for(int i = firstLower; i < len; i += srcCount){
srcChar =(int)value[i];if((char)srcChar >=Character.MIN_HIGH_SURROGATE &&(char)srcChar <=Character.MAX_HIGH_SURROGATE){
srcChar =codePointAt(i);
srcCount =Character.charCount(srcChar);}else{
srcCount =1;}if(localeDependent){
upperChar =ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);}else{
upperChar =Character.toUpperCaseEx(srcChar);}if((upperChar ==Character.ERROR)||(upperChar >=Character.MIN_SUPPLEMENTARY_CODE_POINT)){if(upperChar ==Character.ERROR){if(localeDependent){
upperCharArray =ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);}else{
upperCharArray =Character.toUpperCaseCharArray(srcChar);}}elseif(srcCount ==2){
resultOffset +=Character.toChars(upperChar, result, i + resultOffset)- srcCount;continue;}else{
upperCharArray =Character.toChars(upperChar);}/* Grow result if needed */int mapLen = upperCharArray.length;if(mapLen > srcCount){char[] result2 =newchar[result.length + mapLen - srcCount];System.arraycopy(result,0, result2,0, i + resultOffset);
result = result2;}for(int x =0; x < mapLen;++x){
result[i + resultOffset + x]= upperCharArray[x];}
resultOffset +=(mapLen - srcCount);}else{
result[i + resultOffset]=(char)upperChar;}}returnnewString(result,0, len + resultOffset);}