1

I have an ArrayList like : ArrayList<ArrayList<String>> test

for(int i = 0; i < test.size(); i++) {
    ArrayList temp = test.get(i);
}

It turns out now, that I cannot do Arrays.deepToString(temp.toArray()) since temp is an Object and not < ArrayList< String>>.

Also, I am doing temp1.contains(temp.get()) temp1 and temp2 are actually objects with the same values < ArrayList< String>>. They even have some common ArrayLists within them. However, due to this Object problem, this does not work.

Is there any way by which I can basically return an ArrayList or so instead of an object so that I can get the .contains() method to work. As I said... the ArrayList within temp has the same number of columns, some with the same values.

Please help me out.

4

3 回答 3

3
ArrayList temp = test.get(i);

应该

ArrayList<String> temp = test.get(i);
于 2013-07-04T06:46:38.457 回答
1

如果您参数化 ArrayList 并将返回类型传递给toArray()它应该可以正常工作。

for(int i = 0; i < test.size(); ++i){
    ArrayList<String> temp = test.get(i);
    temp.toArray(new String[]{});
}

现在toArray()返回一个 String[]

于 2013-07-04T06:55:29.833 回答
0
    ArrayList<ArrayList<String>> test=new ArrayList<>();
    ArrayList<String> list=new ArrayList<>();
    list.add("a");
    list.add("b");
    list.add("c");
    test.add(list);
    ArrayList<String> temp=new ArrayList<>();
    for(ArrayList<String> arr:test) {
        temp = arr;
    }
于 2013-07-04T06:53:06.433 回答