views:

131

answers:

3

Hi i have set of 2D arrays and i want store all 2D arrays into single list how can do this in java?

+1  A: 

e.g. or what do you mean

int[][] a2d = new int[15][15];
int[][] b2d = new int[10][10];
List<int[][]> list2d = new ArrayList<int[][]>(10);
list2d.add(a2d);
list2d.add(b2d);

or do you mean you have a Set<int[][]> then you can simply do what tpierzina suggested

List<int[][]> list2d = new ArrayList<int[][]>();
list2d.addAll(nameOfYourSetVariable);

or

List<int[][]> list2d = new ArrayList<int[][]>(nameOfYourSetVariable);
jitter
List <double[][]> twoDimArrayList=new ArrayList<double[][]>();i have done like this but it is showing error arraylist cannot be resolved type
Have you imported ArrayList? I mean `import java.util.ArrayList;`
Adeel Ansari
add `import java.util.*;` to the top of your file
jitter
+1  A: 
List<String[][]> myFunc( Set<String[][]> s ) {
  List<String[][]> l = new ArrayList<String[][]>( s.length() );
  l.addAll( s );
  return l;
}
tpierzina
+1  A: 

Can't you just pass the set into a list like so:

 int [][]a = new int[3][3];
 Set<int[][]> set = new HashSet<int[][]>();
 set.add(a);
 ArrayList<int[][]> list = new ArrayList<int[][]>(set);

Or am I not understanding your question.

brianegge