使用 Java 将多维数组添加到数组列表 [英] Add Multidimensinal array to an array list using Java

查看:28
本文介绍了使用 Java 将多维数组添加到数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法(函数),它应该将一个 (8*6)Array 添加到一个数组列表中.函数被多次调用.

I am having a method(function) that is supposed to add a (8*6)Array to an Array list. Function is called several times.

int [][] KeySelection = new int [8][7];

  for(int i=0;i<KeySelection.length;i++){
  for(int j=0;j<KeySelection[0].length;j++){
      KeySelection[i][j] = (int) (Math.random () * 2);

     }
  }

每次调用此函数时,都会完成一个全新的 KeySelection 数组.我现在需要的是声明一个数组列表,以便它可以将所有 KeySelection 数组存储在该列表中.

Each time this function is called a totally new KeySelection Array is done. What i need now is to declare an array list so that it could store all the KeySelection Arrays in that list.

这样当我需要第一个 KeySelection 表时,我可以在数组列表的第一个索引中找到它.有人可以帮忙吗

So that when i need the first KeySelection Table i could find it in the first index of the Array list. Could somebody Help

推荐答案

创建int[][]类型的ArrayList:-

List<int[][]> list = new ArrayList<int[][]>();

然后,在创建后将您的数组添加到此列表中:-

And then, add your array to this list after creation: -

list.add(keySelection);

注意:-变量名应该以小写字母开头.

NOTE: - Variable name should start with lowercase letters.

这篇关于使用 Java 将多维数组添加到数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆