Convert 2d string array to ArrayList in android

How to convert 2d string array to ArrayList ? I have a 2d array of strings, how can I hide it in a list of arrays ???

+4
source share
3 answers

If you need a complete list of items, just do it. There is probably an easy way

  ArrayList<String> list = new ArrayList<String>(); for (int i=0; i < array_limit ; i++) for (int j=0 ; j < array_limit; j++) list.add(your_array[i][j]); 
+3
source
 public static ArrayList<String> rowsToString(String[][] data) { ArrayList<String> list = new ArrayList<String>(); for(int i = 0; i < data.length; i++) { String row = Arrays.toString(data[i]); list.add( row.substring(1, row.length()-1) ); } return list; } 
+1
source

Depends on what exactly you want. Try:

 for(int i=0;i<a.length;i++){ newList.add(new ArrayList<String>()); for(int j=0;j<a.length;j++){ newList.get(i).add(a[i][j]); } } 

Then you can access the elements, for example:

 newList.get(1).get(2); 
+1
source

Source: https://habr.com/ru/post/1441294/


All Articles