String Objects &
Method Practice

Create strings, call methods, save results, and test what really changes.

Task 1: Build Strings

Create one string with new and one with the shorter form

StringBuild.java
java

Task 2: Call Methods

Start with one string, then write these four method calls

Start Here
String word = "coding";
Goal 1
Length

Print the number of characters in word.

Goal 2
Short Piece

Print word.substring(1, 4).

Goal 3
To the End

Print word.substring(2).

Goal 4
Find a Letter

Print the first index of "d".

Task 3: Store Results

Save each returned value in a variable with the correct type

StringResults.java
java

Task 4: Immutable Check

Run the code and compare the two printed lines

ImmutableCheck.java
java

Task 5: null or Empty?

Test an empty string and a null reference

NullOrEmpty.java
java

Bonus Challenge

Secret Message

Build one short program that uses several string methods in the same flow.

  • 1. Create a sentence such as "robot factory ready".
  • 2. Take out one word fragment with substring().
  • 3. Use indexOf() to find one letter position.
  • 4. Use equals() to test whether one result matches your target text.
  • 5. Print all final results clearly.