Misconception: Students incorrectly assume that Java’s substring method is destructive and wrongly anticipate the original string will change.

  • 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"

More about this tip

External Source

Interview with Suzy Crowe

Other Tips By