我正在尝试添加到3d数组中,如下所示:
ArrayList<ArrayList<ArrayList<String>>> bigList = new ArrayList<>();
ArrayList<ArrayList<String>> smallList = new ArrayList<>();
但是当我添加如下内容时
bigList.add(smallList);
它只会覆盖以前的条目
我该如何解决?
答案 0 :(得分:0)
你的方法有点困惑。以下是如何将ArrayLists添加到3d ArrayList的工作示例:
ArrayList<ArrayList<ArrayList<String>>> masterList = new ArrayList<>();
ArrayList<ArrayList<String>> middleList1 = new ArrayList<>();
ArrayList<ArrayList<String>> middleList2 = new ArrayList<>();
ArrayList<String> innerList1 = new ArrayList<>();
ArrayList<String> innerList2 = new ArrayList<>();
ArrayList<String> innerList3 = new ArrayList<>();
ArrayList<String> innerList4 = new ArrayList<>();
innerList1.add("String 1");
innerList1.add("String 2");
innerList2.add("String 3");
innerList2.add("String 4");
innerList3.add("String 5");
innerList3.add("String 6");
innerList4.add("String 7");
innerList4.add("String 8");
middleList1.add(innerList1);
middleList1.add(innerList2);
middleList2.add(innerList3);
middleList2.add(innerList4);
System.out.println(masterList.size()); //output: 0
masterList.add(middleList1);
System.out.println(masterList.size()); //output: 1
masterList.add(middleList2);
System.out.println(masterList.size()); //output: 2
答案 1 :(得分:-2)
尝试100%
ArrayList<String> biglist = new ArrayList();
ArrayList<String> list = new ArrayList();
ArrayList<String> e1 = new ArrayList();
e1.add("aaa");
list.add(e1);
biglist.add(list);
System.out.println(biglist.get(0).get(0).get(0));
> //display aaa
答案 2 :(得分:-3)
我不是百分百肯定,但看看这是否有帮助:
String[][][] bigList=new String[how"wide"][how"tall"][how"fat"]