String
constructor is inefficient, use raw string literals directly instead72
73 for (String j : paramStrings) {
74 String[] vals = j.split(":");
75 params.put(vals[0].toString(), new String(vals[1]));76 }
77
78 var configElem = new ConfigData();
Description
Creating a String
using object creation wastes memory because the new String
object so constructed will be functionally indistinguishable from the String
value passed as a parameter. Just use the string directly.
Bad Practice
String a = new String("abc");
Recommended
String a = "abc";
References
- Spotbugs - DM_STRING_CTOR