...
This noncompliant code example ignores the return value while making use of the String.replace method. As a result, the original string is not updated even though it seems otherwise. The String.replace() method does not modify the state of the String but instead, returns a reference to a new String object with the replacements in effect.
| Code Block | ||
|---|---|---|
| ||
public class Ignore {
public static void main(String[] args) {
String original = "insecure";
original.replace( 'i', '9' );
System.out.println(original);
}
}
|
...