I have a 2d matrix like this String[][] arr; and I want to convert it into List<List<String>>arr;. How can I do achieve that?
I saw some similar answers related to my question on this community but they were about how to convert a matrix in List<T>.
>Solution :
For that purpose, you can make use of the asList() static method of the Arrays utility class. Simply iterate over the source array and apply asList() to every nested array.
List<List<String>> result = new ArrayList<>();
for (String[] next: arr) {
result.add(Arrays.asList(next));
}
Note, that asList() method returns a list backed by the specified array, and therefore it can’t be changed in size (you can sort it, reassign values, but its add() and remove() methods will throw an UnsupportedOperationException). Changes that have been done to the list will be reflected in the source array and vice-versa.