Hi All,
can somebody make me clear this way? How it is possible to write better ?
pulbic class Log
{
public static void log(String s, String t)
{
System.out.println("heading" + s + "trailer" + t);
}
}
The cost of Strings: The String concatenation operator + looks innocent but involves a lot
of work. The compiler can efficiently concatenate constant strings, but a variable string
requires considerable processing. For example, if s and t are String variables:
System.out.println("heading" + s + "trailer" + t);
this requires a new StringBuffer, appending arguments, and converting the result back to a
String with toString( ). This costs both space and time. If you're appending more than one
String, consider using a StringBuffer directly, especially if you can repeatedly reuse it in a
loop. Preventing the creation of a new StringBuffer on each iteration saves the object
creation time of 980 seen earlier. Using substring( ) and the other String methods is usually
an improvement. When feasible, character arrays are even faster. Also notice that
StringTokenizer is costly because of synchronization.
THX
Garp
can somebody make me clear this way? How it is possible to write better ?
pulbic class Log
{
public static void log(String s, String t)
{
System.out.println("heading" + s + "trailer" + t);
}
}
The cost of Strings: The String concatenation operator + looks innocent but involves a lot
of work. The compiler can efficiently concatenate constant strings, but a variable string
requires considerable processing. For example, if s and t are String variables:
System.out.println("heading" + s + "trailer" + t);
this requires a new StringBuffer, appending arguments, and converting the result back to a
String with toString( ). This costs both space and time. If you're appending more than one
String, consider using a StringBuffer directly, especially if you can repeatedly reuse it in a
loop. Preventing the creation of a new StringBuffer on each iteration saves the object
creation time of 980 seen earlier. Using substring( ) and the other String methods is usually
an improvement. When feasible, character arrays are even faster. Also notice that
StringTokenizer is costly because of synchronization.
THX
Garp