This question already has an answer here:
- Convert ArrayList<String> to String[] array [duplicate] 6 answers
- Convert list to array in Java 11 answers
List<String> list = getNames();//this returns a list of names(String).
String[] names = (String[]) list.toArray(); // throws class cast exception.
I don't understand why ? Any solution, explanation is appreciated.