// Project: InstanceMethods // No modules defined // Source code file StringTest.java // Test some methods and other features // of the String class. public class StringTest { public static void main(String[] args) { // Create new String objects in various ways. String a = "wolf"; char[] b = {'f', 'o', 'x'}; String c = new String(b); // Define String reference variables. // Strings to be created or assigned later. String e, f; // Test two ways to concatenate strings. System.out.println(a + " " + c); System.out.println(a.concat(c)); System.out.println( ); // Illustrate length and substring methods. e = a + c + "abcdefg"; System.out.println(e + " " + e.length( ) + " " + e.substring(2, 7)); // format is a static method of the String class. int x = 3956; f = String.format("%s***%d", a, x); System.out.println(f); System.out.println( ); // Compare behavior of Equals and ==. String h = new String("wolf"); String i = a; System.out.println(a.equals(h) + " " + (a == h)); System.out.println(a.equals(i) + " " + (a == i)); } }