1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
class StringToChar{ public static void main(String args[]){ String str = new String("HELLO HOW ARE YOU"); char ch[] = new char[str.length()]; for(int i=0;i<(str.length());i++){ ch[i] = str.charAt(i); } for(char i : ch) System.out.print(i); } } |
Discussion
In above code sample we have used str.length() where length() is a function but for array length we use array.length where length is property.