- Students don’t realize that calling
substring
in Java won’t change the variable. - For example, in Line 2 below they might expect that the variable
myString
would be changed.
public static void main(String[] arg){
String myString = new String("abcdefghijkl");
myString.subSequence(2, 4); // LINE 2// prints "abcdefghijkl" instead of "cd"
System.out.println(myString);
}