标签:bsp com eth his hat pil ace compiler cte
This method passes a constant literal String
of length 1 as a parameter to a method, that exposes a similar method that takes a char
. It is simpler and more expedient to handle one character, rather than a String
.
Instead of making calls like: String myString = ...
Replace the single letter
if (myString.indexOf("e") != -1) {
int i = myString.lastIndexOf("e");
System.out.println(myString + ":" + i); //the Java compiler will use a StringBuilder internally here [builder.append(":")]
...
return myString.replace("m","z");
}String
s with their char
equivalents like so:String myString = ...
if (myString.indexOf(‘e‘) != -1) {
int i = myString.lastIndexOf(‘e‘);
System.out.println(myString + ‘:‘ + i); //the Java compiler will use a StringBuilder internally here [builder.append(‘:‘)]
...
return myString.replace(‘m‘,‘z‘);
}
Performance - Method passes constant String of length 1 to character overridden method
标签:bsp com eth his hat pil ace compiler cte
原文地址:http://www.cnblogs.com/winner-0715/p/7327334.html