I am new to Java and trying to learn conversion from char ArrayList to char array. I am having some hard time to convert this.
List<Character> code = new ArrayList<Character>();
code.add("A");
code.add("B");
code.add("C");
This will display as [A, B, C]. What I want to do is to convert this array list to char[] array.
What I tried was the following:
char[] list = null;
for(int i=0; i<code.size(); i++){
list[i] = code.get(i);
System.out.println(list[i]); // this has the error
}
The error I am getting is java.lang.NullPointerException.
I searched online but I couldn't find a "better" solution. Most of them are a conversion from string to char or vice versa. Perhaps I am missing some important knowledge about this.
Again, I am new to Java and any help will be appreciated!.
Listinterface includes atoArraymethod that does this conversion for you. Also, be careful about the difference between single and double quotes.