I am trying to create an ArrayList of Object[] from an Object[][] perform some changes and then getting a new Object[][] with the changes made.
However I get this compile error:
error: incompatible types: Object[] cannot be converted to Object[][]
when performing this:
protected Object[][] data;
fillData();
ArrayList dlist= new ArrayList<Object[]>( Arrays.asList(data) ); //NO COMPILE ERROR
Object[] example=new Object[2]; //just to use in toArray()
String [] args= {"new data 1","new data 2"};//yeah just a typo thanks Oscar
dlist.add( args ); //Sending String instead of Object is legal thanks Oscar.
data= dlist.toArray( example ); //COMPILER ERROR incompatible...
I am using the wrong statement with no compiler error:
ArrayList dlist= new ArrayList<Object[]>( Arrays.asList(data) );
because the output is Object[] instead of Object[][] which is what i want
Thanks for your help.
List<Object[]> dlist= new ArrayList<Object[]>( Arrays.asList(data) );compiles for me. What's your exact problem? Probably you didn't add the necessary imports or something.dlist.add(<whatever>)works because you have declaredArrayList dlistwhich is raw, similar to declareArrayList<Object> dlistwhich means you can store anything there.