// Stringing.java (c) 2004 Kari Laitinen // http://www.naturalprogramming.com // 2002-11-27 File created. // 2004-10-09 Last modification. // This program demonstrates (among other things): // - how a String object can be created from an array of type char // - how s String object can be converted to an array of type char // - how an array of type char can be printed by using the // new kind of Java for loop class Stringing { public static void main( String[] not_in_use ) { String abcdefgh_string = "abcdefgh" ; char[] xxxxxxxx_array = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' } ; String xxxxxxxx_string = new String( xxxxxxxx_array ) ; String defgzzzz_string = abcdefgh_string.substring( 3, 7 ) ; defgzzzz_string = defgzzzz_string + "zzzz" ; String text_to_print = " " + abcdefgh_string + " " + xxxxxxxx_string + " " + defgzzzz_string + " " ; System.out.print( "\n" ) ; int character_index = 0 ; while ( character_index < text_to_print.length() ) { System.out.print( text_to_print.charAt( character_index ) ) ; character_index ++ ; } System.out.print( "\n\n" ) ; char[] characters_to_print = text_to_print.toCharArray() ; for ( char character_in_text : characters_to_print ) { System.out.print( " " + character_in_text ) ; } System.out.print( "\n" ) ; character_index = text_to_print.length() ; while ( character_index > 0 ) { character_index -- ; System.out.print( " " + text_to_print.charAt( character_index ) ) ; } } } /**** Multiline comment: The following code was once used to print the characters of string text_to_print: StringCharacterIterator character_in_text ; character_in_text = new StringCharacterIterator( text_to_print ) ; while ( character_in_text.getIndex() < character_in_text.getEndIndex() - 1 ) { System.out.print( " " + character_in_text.next() ) ; } *****/