The trim String () method

Role in trim Stirng () method is to remove the string of the front and rear spaces.

String str = " test trim ";

System.out.println(str.trim());

It will print out the console  test before and after the trim there are no spaces

/ ** Attach trim () source code * /

String TRIM public () { 
int len = value.length;
int ST = 0;
char [] Val = value; / * * Avoid the getfield of opcode /

the while ((ST <len) && (Val [ST] <= '') ) {// read the number of spaces in front of the string
ST ++;
}
the while ((ST <len) && (Val [len -. 1] <= '')) {// read the number of spaces behind the string
len-- ;
}
return ((ST> 0) || (len <value.length)) the substring (ST, len):? the this; // number by the number of spaces in front of and behind the interception string
}

 

Guess you like

Origin www.cnblogs.com/huoyufei/p/11125880.html