1   // Example 8.2 joi/examples/StringDemo.java  
2   //
3   //
4   // Copyright 2003 Bill Campbell and Ethan Bolker
5   
6   // A class illustrating Strings 
7   // 
8   // %> java StringDemo
9   // certainly = "yes!"
10  // bankName = "Dewey, Cheatham and Howe"
11  // bankName.charAt( 0 ) = D
12  // bankName.charAt( 5 ) = ,
13  // bankName.indexOf('e') = 1
14  // bankName.indexOf('e', 6) = 9
15  // bankName.indexOf('x') = -1
16  // "cake".compareTo("care") = -7
17  // bankName.substring( 7, 12 ) = Cheat
18  // bankName.substring( 7 ) = Cheatham and Howe
19  // bankName.toUpperCase() = "DEWEY, CHEATHAM AND HOWE"
20  // bankName.replace('e', 'x') = "Dxwxy, Chxatham and Howx"
21  // bankName.concat("!") = "Dewey, Cheatham and Howe!"
22  // "  x y z \t\b".trim() = "x y z"
23  // %>
24  
25  public class StringDemo 
26  {
27      public static void main( String[] args ) 
28      {
29          Terminal t = new Terminal();
30  
31          String bankName = "Dewey, Cheatham and Howe";
32          String alias = new String( bankName );
33          char[] carray = {'y', 'e', 's', '!'};
34          String certainly = new String(carray);
35          
36          t.println( "certainly = \"" + certainly + "\"" );
37  
38          t.println( "bankName = \"" + bankName + "\"" );
39          t.println( "bankName.charAt( 0 ) = " + bankName.charAt( 0 ) );
40          t.println( "bankName.charAt( 5 ) = " + bankName.charAt( 5 ) );
41  
42          t.println("bankName.indexOf('e') = " + bankName.indexOf('e'));
43          t.println("bankName.indexOf('e', 6) = " + 
44                    bankName.indexOf('e', 6));
45          t.println("bankName.indexOf('x') = " + bankName.indexOf('x'));
46          
47          t.println( "\"cake\".compareTo(\"care\") = " +
48                     "cake".compareTo("care") );
49  
50          t.println( "bankName.substring( 7, 12 ) = " +
51                     bankName.substring( 7, 12 ) );
52          t.println( "bankName.substring( 7 ) = " +
53                     bankName.substring( 7 ) );
54  
55          t.println( "bankName.toUpperCase() = \"" +
56                     bankName.toUpperCase() + "\"" );
57          t.println( "bankName.replace('e', 'x') = \"" +
58                     bankName.replace('e', 'x') + "\"" );
59          t.println( "bankName.concat(\"!\") = \"" +
60                     bankName.concat("!") + "\"" );
61          t.println( "\"  x y z \\t\\b\".trim() = \"" +
62                     "  x y z \t\b".trim() + "\"" );
63      }
64  }
65