Performance - Method passes constant String of length 1 to character overridden method

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Performance - Method passes constant String of length 1 to character overridden method相关的知识,希望对你有一定的参考价值。

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 = ... 
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");
}
Replace the single letter Strings 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的主要内容,如果未能解决你的问题,请参考以下文章

Development of a High Coverage Pseudotargeted Lipidomics Method Based on Ultra-High Performance Liqu

jQuery ajax GET 返回 405 Method Not Allowed

将函数传递给装饰器

使用带或不带括号的 python 装饰器

thinkphp自动验证和自动完成

input标签样式修改