Issue
I have am X n
two dimensional array of an Object say Foo
. So I have Foo[][] foosArray
. What is the best way to convert this into a List<Foo>
in Java?
Solution
This is a nice way of doing it for any two-dimensional array, assuming you want them in the following order:
[[array[0]-elems], [array[1]elems]...]
public <T> List<T> twoDArrayToList(T[][] twoDArray) {
List<T> list = new ArrayList<T>();
for (T[] array : twoDArray) {
list.addAll(Arrays.asList(array));
}
return list;
}
Answered By - Keppil