1. Trim Performance
Feature strips the string from the end of the space, preventing unnecessary whitespace from causing an error.
public class Trimtest{public static void Main (string[] args) {String str1= "CJC"; String str2= "C JC"; System.out.println (Str1.length ()); System.out.println (Str1.trim (). Length ()); System.out.println (Str2.length ()); System.out.println (Str2.trim (). Length ());}}
2, substring, replaceall, and indexof functions
Str.substring (n); cut off the first n characters of str;
Str.replaceall ("[AB]", "_"); the characters ' a ' and ' B ' that appear in STR are replaced by ' _ ';
Str.indexof ("good"); if Str contains good, the first letter of the good ' G ' is returned at index position in str (starting from 0).
public class Trimtest{public static void Main (string[] args) {int num; String str1= "CJC is a good//boy!"; System.out.println (STR1); str1=str1.substring (7); System.out.println (STR1); Num=str1.indexof ("good"); SYSTEM.OUT.PRINTLN (num); Str1=str1.replaceall ("[/A]", "_"); System.out.println (STR1);}}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Java string Classification Trim,substring,replaceall,indexof use features