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‘);
}

时间: 2024-10-06 09:07:06

Performance - Method passes constant String of length 1 to character overridden method的相关文章

WCF常见异常-The maximum string content length quota (8192) has been exceeded while reading XML data

异常信息:The maximum string content length quota (8192) has been exceeded while reading XML data 问题:调用第三方的WCF服务,产生上述异常信息 分析: 在公布WCF host端时,要确保host端以及客户端的设置允许一定大小的数据传输. 如果未设置传输大小,maxStringContentLength默认大小为8192. 1)如果第三方服务未设置maxStringContentLength或者设置的maxS

The maximum string content length quota (8192) has been exceeded while reading XML data

原文:The maximum string content length quota (8192) has been exceeded while reading XML data 问题场景:在我们WCF服务发布后,我们要确保服务端以及客户端的配置文件允许合适大小的传输设置.笔者在发布WCF服务时,服务端的绑定未做传输大小的设置(采用了默认,maxStringContentLength默认大小为8192),而我们在传输序列化的数据时,大小超过了这个限制. 读取 XML 数据时,超出最大字符串内容

关于string的length

在C++里面,std::string的length()返回的是字节数,与编码方式有关. 1 int main() 2 { 3 std::string s = "我是中国人"; 4 std::cout << s.length() << std::endl; 5 std::cout << strlen(s.c_str()) << std::endl; 6 } 上面的代码,使用GB2312编码,输出结果是10和10. 而在C#里面,string

ord() expected string of length 1, but int found

源代码是这样: s=b'^SdVkT#S ]`Y\\!^)\x8f\x80ism' key='' for i in s:     i=ord(i)-16     key+=chr(i^32) print (key) 运行后出现了问题:ord() expected string of length 1, but int found 之所以出现这个问题,是在字符串转换过程中出现了一个小错误,在一系列百度和谷歌后,发现概念还是很迷糊,但是在曙光大佬的解答后,明白了怎么处理,就是在s后加"",

tcl之string操作-length/index/range/replace

Changing the Overridden Method&rsquo;s Characteristics

修改重写方法的特征 在大多数情况下,我们重写(override)一个 virtual 方法是为了改变它的实现.然后,有时我们却想改变该 virtual 方法的其他的特征,这往往会带来一系列问题. 1)改变方法的返回值类型 通常,子类在重写方法时,要保持与父类一致的函数原型,方法的实现可以改变,但是原型需要保持不变. 然而,事实却并非如此.在C++中,如果父类的 virtual 方法的返回值类型是某个类(假定为类A)的指针或者引用,那么在子类中 override 该方法时,可以将其返回值改变为子类

iOS -- warnings

Semantic Warnings Warning Message -WCFString-literal input conversion stopped due to an input byte that does not belong to the input codeset UTF-8 -WNSObject-attribute         __attribute ((NSObject)) may be put on a typedef only, attribute is ignore

IOS 警告 收集

Semantic Warnings Warning Message -WCFString-literal input conversion stopped due to an input byte that does not belong to the input codeset UTF-8 -WNSObject-attribute __attribute ((NSObject)) may be put on a typedef only, attribute is ignored -Wabst

IOS 警告 汇总

Semantic Warnings Warning Message -WCFString-literal input conversion stopped due to an input byte that does not belong to the input codeset UTF-8 -WNSObject-attribute __attribute ((NSObject)) may be put on a typedef only, attribute is ignored -Wabst