first, thecommon method of StringBuilder class in Java
Append (parameter): Append content to the end of the current StringBuilder object
Insert (position, parameter): Inserts the content into the specified position of the StringBuilder object
ToString (): Converts a StringBuilder object to a String object
Length (): Gets the length of the string
toLowerCase (): Convert to lowercase
charAt (int i): Gets the value indexed to I
GetBytes (): Convert to byte array
indexOf (int ch): Find the ch character where the string first appears
IndexOf (String str): Find the first occurrence of the STR string in the position of the string
Lastindexof (int ch): Find the CH character at the last occurrence of the string
LastIndexOf (String str): Finds the position of the STR string at the last occurrence of the string
Split (): Splits the string into substrings;
1 "Append and insert operations for StringBuilder objects
1 StringBuilder str=new StringBuilder ("Hello"); 2 str.append ("World"); 3 str.append ("!") ); 4 System.out.println (Str.length ()); 5 System.out.println (str);
6 Str.insert (12. "!");
7 Sting str2=str.tostring ();
8 System.out.println ("After insertion:" +STR2);
Output Result: 12
Hello world!
After insertion: Hello world!!
Note : StringBuffer and StringBuilder function the same, but StringBuffer is thread-safe, and StringBuilder does not implement thread-safe functionality, so performance is slightly higher. Therefore, in general, if you need to create a variable-content string object, you should consider using the StringBuilder class as a priority.
Second,"= =" and equals () What is the difference?
= =: Determines whether the first address in memory of two strings is the same, that is, whether it is the same string object
Equals (): Compares the content stored in two string objects in a consistent
1 String str1= "I love You"; 2 string str2=new string ("I Love You"); 3 System.out.println ("str1 and str2 have the same memory address?") "+ (str1==str2)); 4 System.out.println ("str1 and str2 have the same content? "+str1.equals (STR2));
Output Result: false
True
Some core content of strings in Java