简体   繁体   English

Java中的2D数组列表

[英]list of 2D array in java

我有一组2D数组,我想将所有2D数组存储到单个列表中,如何在Java中做到这一点?

eg 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 或者您是说您有一个Set<int[][]>那么您可以简单地执行tpierzina建议的操作

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

or 要么

List<int[][]> list2d = new ArrayList<int[][]>(nameOfYourSetVariable);
List<String[][]> myFunc( Set<String[][]> s ) {
  List<String[][]> l = new ArrayList<String[][]>( s.length() );
  l.addAll( s );
  return l;
}

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. 还是我不明白你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM