All transfer procedures between activities appear to be based on ArrayList (even so-called simplified ones, like TinyDB), not Array. My app uses Array (int[ ][ ]). So I'm looking for a way to convert Array into ArrayList, so I can apply one of these transfer procedure.
            Asked
            
        
        
            Active
            
        
            Viewed 70 times
        
    1 Answers
1
            
            
        If you want to preserve the structure of the data, you'll need a List<Integer[]>.
Converting a multi-dimensional array to a single-dimensional list will cause data loss.
You could also use a List<List<Integer>>, which would essentially be the same as above.
If you want to preserve your data:
private void foo(int[][] myArrayOfArrays) {
    List<Integer[]> foos = new ArrayList<>();
    for (int myArray[] : myArrayOfArrays) {
        foos.add(myArray);
    }
}
Alternatively, if you don't mind the data loss, you could just list all the items:
private void bar(int[][] foobar) {
    List<Integer> foos = new ArrayList<>();
    for (int[] myArray : foobar) {
        for (int i : myArray) {
            foos.add(i);
        }
        // Possibly add this as a delimiter?
        foos.add(Integer.MAX_VALUE);
    }
}
 
    
    
        SimonC
        
- 1,547
- 1
- 19
- 43
