// Helene Martin, CSE 142 // Demonstrates use of the String methods. public class StringDemo { public static void main(String[] args) { String hobby = "ASCII art"; int spaceIndex = hobby.indexOf(" "); int hobbyLength = hobby.length(); // grab the first word of any String with at least two words String firstWord = hobby.substring(0, spaceIndex); // hobbyFirst.toLowerCase(); -- doesn't do anything! A new string is returned hobbyFirst = hobbyFirst.toLowerCase(); // same pattern as x = x + 1 System.out.println(hobbyFirst); System.out.println(hobby); // hasn't been modified // String methods can be chained System.out.println(hobby.substring(0, 2).toLowerCase()); } }