How to turn List of arrays into two dimensional array in Java?
//Prepare the list
List<Object[]> conf = new LinkedList<Object[]>();
conf.add(new Object[]{ "FOO", "BAR"});
conf.add(new Object[]{ "FOO", "BAR"});
I tried:
Object[][] array = (Object[][]) conf.toArray(new Object[0]);
But it fails at ClassCastException:
java.lang.RuntimeException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [[Ljava.lang.Object;
Object[]is anObjectso aList<Object[]becomes anObject[]because you passing in anObject[]to the method.