More about Strings

This chapter accompanies the previous one. Read it for even more info on Strings.

1. More about Strings

String objects are frequently used in programs. This chapter provides extra practice in using them.

Note: the String class is one of the classes that Advanced Placement Computer Science students are expected to know well. This chapter was written after the author observed an unfortunate number of mistakes involving Strings in the AP-CS 2008 examination.

Chapter Topics:

      • Strings are Immutable
      • Indexing Strings
      • substring()
      • indexOf()

Question 1:

What does the following code write?

public class ImmDemo
{
  public static void main ( String[] args )
  {
    String str = new String("I recognize the vestiges of an old flame.");
    str.substring( 16 );
    System.out.println( str );
  }
}

Source: Bradley Kjell, http://programmedlessons.org/Java9/chap45/ch45_01.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 License.