How to retrieve data from ArrayList consists of array objects

前端 未结 6 1447
清歌不尽
清歌不尽 2021-01-23 23:23

My arraylist contains String array objects. How Can I get all values? My code is below,

String cordinates1c,cordinates2l,cordinates2m;                   
String[         


        
相关标签:
6条回答
  • 2021-01-24 00:05

    You can iterate over your List and then use Arrays.toString() or Arrays.deepToString() to print array contents

     for (String[] eachArray : alist) {
         System.out.println("arrayList=" + Arrays.deepToString(eachArray));
     }
    
    0 讨论(0)
  • 2021-01-24 00:05

    Are you looking for something like this ?

    String cordinates1c = "1", cordinates2l = "2", cordinates2m = "3"; 
    String[] array1 = {cordinates1c, cordinates2l, cordinates2m};      
    String[] array2 = {cordinates1c, cordinates2l, cordinates2m};      
    
    List<String []> alist=new ArrayList<String []>();                  
    alist.add(array1);                                                 
    alist.add(array2);                                                 
    for (String[] strings : alist) {                                   
        System.out.println(StringUtils.join(strings));                 
    }  
    

    Output: 123 123

    0 讨论(0)
  • 2021-01-24 00:08

    Hoping that you are trying to print the string in array1

    ArrayList<String> alist= (ArrayList<String>) Arrays.asList(array1);
    

    Now print the data from alist.

    also have a look into alist.addAll(collection)

    But following snippet will add array1 and array2 object to your ArrayList, So retrieval you will get an array object

    alist.add(array1);
    
    alist.add(array2);
    
    0 讨论(0)
  • 2021-01-24 00:09

    Arrays should be printed with the help of Arrays.toString() or Arrays.deepToString().

    import java.util.Arrays;
    public class Test {
        public static void main(String[] args) throws Exception {
            String[][] a = {{"a", "b", "c"}, {"d", "e"}};
            System.out.println(Arrays.deepToString(a));
        }
    }
    
    0 讨论(0)
  • 2021-01-24 00:11
    ArrayList<String[]> l;
    for (String[] a : l) {
        for (String s : a) {
            System.out.println(s);
        }
    }
    
    0 讨论(0)
  • 2021-01-24 00:21
    for(int i=0;i<alist.size();i++) {
    
        for (String a : alist.get(i)) {
            System.out.println(a);
        }
    }
    

    You have to iterate over the array of strings, too.

    0 讨论(0)
提交回复
热议问题