Java

Java

Made by DeepSource

String.substring() call with single 0 index found JAVA-W1077

Anti-pattern
Major
Autofix

Avoid calling String.substring(int) with just 0, as that would effectively just return a copy of the string.

Strings are immutable, and it's possible to copy a string just with its reference. If you absolutely need a new string (for referential identity purposes, maybe), use String's copy constructor.

Bad Practice

String a = "something";
String b = a.substring(0); // not very useful...

Recommended

To actually copy a String, you can construct a new one with String's copy constructor:

String b = new String(a);