// TestingClassString.java (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-04-13 File created. // 2005-04-17 Last modification. import java.util.* ; class TestingClassString { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; String string_object = "ABC" ; String another_string = "abc" ; System.out.print( "\n comparison result: " + string_object.compareToIgnoreCase( another_string ) ) ; String resulting_string = string_object.concat( another_string ) ; System.out.print( "\n " + resulting_string ) ; resulting_string = string_object + another_string ; System.out.print( "\n " + resulting_string ) ; string_object = "ABCDEFG" ; another_string = "CD" ; if ( string_object.contains( another_string ) ) { System.out.print( "\n " + string_object + " contains " + another_string ) ; } if ( string_object.contains( new StringBuilder( another_string ) ) ) { System.out.print( "\n " + string_object + " contains " + another_string ) ; } if ( string_object.indexOf( another_string ) != -1 ) { System.out.print( "\n " + string_object + " contains " + another_string ) ; } char[] some_character_array = { 'H', 'e', 'l', 'l', 'o', '!' } ; //String string_of_characters = String.copyValueOf( // some_character_array ) ; String string_of_characters = new String( some_character_array ) ; System.out.print( "\n " + string_of_characters ) ; another_string = "FG" ; if ( string_object.endsWith( another_string ) ) { System.out.print( "\n " + string_object + " ends with " + another_string ) ; } string_object = "ABCDE" ; another_string = "ABCDE" ; if ( string_object.contentEquals( new StringBuilder( another_string ) ) ) { System.out.print( "\n " + string_object + " content equals " + another_string ) ; } if ( string_object.contentEquals( another_string ) ) { System.out.print( "\n " + string_object + " content equals " + another_string ) ; } int given_integer = 1025 ; String text_to_print = String.format( "\n%06d is %06X hexadecimal", given_integer, given_integer ) ; System.out.print( text_to_print ) ; string_object = "ABCDEFGHIJ" ; char[] array_of_characters = new char[ 50 ] ; string_object.getChars( 3, 6, array_of_characters, 0 ) ; System.out.print( "\n " + new String( array_of_characters, 0, 4 ) ) ; byte[] array_of_bytes = string_object.getBytes() ; System.out.print( "\n " + new String( array_of_bytes ) ) ; //012345678901234567890123456 string_object = "AAAAADDAAADDAAADDAAADDAAADD" ; System.out.print( "\n last index : " + string_object.lastIndexOf( "DD", 14 ) ) ; // In regular expressions: // + means 1 or more // * zero or more String some_string = "BAGDAD" ; String regular_expression = "[A-G]+" ; System.out.print( "\n " + some_string + " matches " + regular_expression + " is " + some_string.matches( regular_expression ) ) ; System.out.print( "\n " + some_string.matches( "[A-G]+" ) ) ; string_object = "\n some text \t\n\n " ; System.out.print( "\n Before trim():" + string_object + "\n After trim(): " + string_object.trim() ) ; int some_integer = 13994 ; System.out.print( "\n The value is " + String.valueOf( some_integer ) ); System.out.print( "\n The value is " + some_integer ) ; System.out.print( "\n\n" ) ; } }