I have a nested arraylist, for example:
[[[1,2],[4,3]],[[5,6],[7,8]]]
I want to convert it into a simple arraylist, so it becomes
[1,2,4,3,5,6,7,8]
Is there a way to do this?
Here is my code:
public static Object toArrayList(ArrayList nested){
boolean bool = false;
while(!bool){
bool = nested instanceof ArrayList;
ArrayList tmp = new ArrayList();
for(Object o : nested){
if(o instanceof Integer){
System.out.println(o);
tmp.add(o);
}else{
tmp.add(toArrayList((ArrayList)o));
}
}
nested = tmp;
}
return nested;
}
However, when I run it, it doesn't convert it, just returns the same thing.