I have this code and I want to put the string I have in a char array in java, but the problem I have is whenever I use toCharArray() the array reduces its index so, what can I do to keep the array by the same original index?
public static void main(String[] args) {
String str = "cat";
char[][] carray;
carray = new char[5][5];
char[] chararray = new char[5];
chararray = str.toCharArray();
for(int i=0;i<5;i++){
carray[i][0] = chararray[i];
}
System.out.println(carray);
for(int i=0;i<5;i++){
System.out.println("65"+carray[i][0]);
}
toCharArraydoesn't alter index positions. Andcatis only 3 letters, not 5. Plus, you do not need achar[][]to convert a string to a char array