1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public class MainClass { public static void main( String args[] ) { String s1 = "hello there" ; char charArray[] = new char [ 5 ]; System.out.printf( "s1: %s" , s1 ); for ( int count = s1.length() - 1 ; count >= 0 ; count-- ) System.out.printf( "%s " , s1.charAt( count ) ); // copy characters from string into charArray s1.getChars( 0 , 5 , charArray, 0 ); System.out.print( "\nThe character array is: " ); for ( char character : charArray ) System.out.print( character ); } } |
s1: hello theree r e h t o l l e h
The character array is: hello