declaring a character array in java code example Example: java string to char array String str = "example"; char[] ch = str.toCharArray();