CHAPTER 29B — More about Strings

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to home page   go to next page

created: 06/12/2008

CHAPTER 29B — More about Strings

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

Chapter Topics:

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

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 APCS 2008 examination.

QUESTION 1:

What does the following code write?

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 );
  }
}