public class StringConstructors
1: // Fig. 29.1: StringConstructors.java
2: // String class constructors.
3:
4: public class StringConstructors
5: {
6: public static void main( String args[] )
7: {
8: char charArray[] = { 'b', 'i', 'r', 't', 'h', ' ', 'd', 'a', 'y' };
9: String s = new String( "hello" );
10:
11: // use String constructors
12: String s1 = new String();
13: String s2 = new String( s );
14: String s3 = new String( charArray );
15: String s4 = new String( charArray, 6, 3 );
16:
17: System.out.printf(
18: "s1 = %s\ns2 = %s\ns3 = %s\ns4 = %s\n",
19: s1, s2, s3, s4 ); // display strings
20: } // end main
21: } // end class StringConstructors
22:
23:
24: /**************************************************************************
25: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
26: * Pearson Education, Inc. All Rights Reserved. *
27: * *
28: * DISCLAIMER: The authors and publisher of this book have used their *
29: * best efforts in preparing the book. These efforts include the *
30: * development, research, and testing of the theories and programs *
31: * to determine their effectiveness. The authors and publisher make *
32: * no warranty of any kind, expressed or implied, with regard to these *
33: * programs or to the documentation contained in these books. The authors *
34: * and publisher shall not be liable in any event for incidental or *
35: * consequential damages in connection with, or arising out of, the *
36: * furnishing, performance, or use of these programs. *
37: *************************************************************************/