* ** Unchangeable string
Every method in the string class that seems to modify the string value is actually creating a new String object. * ** For simple string operations in stringbuilder, you can use Java operators +, complex String concatenation operations (such as loops). stringbuilder should be used first, because if the default operators are used, in the loop body, the Java compiler will create a new stringbuilder to operate the string at each loop, which is less efficient. * ** Format the output.
Public class simpleformat {
Public static void main (string [] ARGs ){
Int x = 5;
Double Y = 5.332542;
// The old way:
System. Out. println ("Row 1: [" + x + "" + Y + "]");
// The new way:
System. Out. Format ("Row 1: [% d % F] \ n", x, y );
// Or
System. Out. printf ("Row 1: [% d % F] \ n", x, y );
}
}/* Output:
Row 1: [5, 5.332542]
Row 1: [5, 5.332542]
Row 1: [5, 5.332542]
Java The. util. formatter class implements the new Formatting Function string. Format () to format strings.
* ** Regular Expression