/** String objects */ public class TestString2 { public static void main(String[] args) { String text = "Mississippi"; int midIndex = text.length()/2; System.out.println("middle char = " + text.charAt(midIndex)); int startIndex = text.indexOf("i", 2); int endIndex = text.lastIndexOf('p') + 1; String subtext = text.substring(startIndex, endIndex); System.out.println(subtext); String newText = text.replace(subtext, "our"); System.out.println("state 1 = " + text); System.out.println("state 2 = " + newText); } }