14.3.1 String Constructors
Class String provides constructors for initializing String objects in a variety of ways. Four of the constructors are demonstrated in the main method of Fig. 14.1.
Click here to view code image
1 // Fig. 14.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