I try to implement a hashmap like HashMap<String,MyBigList>
But I can't form my MyBigList. The following is the exact HashMap i'm trying to create.
{word=[ [1, [0, 2] ], [ 2, [2]] ], word2=[ [ 1, [1] ] ]}
I want a big list of single lists like the following
[ [single list], [single list], .. ]
and the single list containing an int and a list of ints
[single list] = [1, [0,2]]
I tried using an ArrayList inside an ArrayList inside an ArrayList, but it didn't work.
I even tried creating a new class having as members an int
, and a ArrayList<Integer>
but it didn't work either.
import java.util.ArrayList;
import java.util.HashMap;
public class NewClass {
int id;
ArrayList<Integer> posList;
public NewClass(){
this.id = 0;
this.posList = new ArrayList<Integer>();
}
public NewClass(int _id, int a, int b){
id = _id;
this.posList = new ArrayList<Integer>();
posList.add(a);
posList.add(b);
}
public String toString(){
return "" + this.id + " " + this.posList;
}
public static void main(String[] args) {
NewClass n = new NewClass(1,2,3);
HashMap<String,ArrayList<ArrayList<NewClass>>> map = new HashMap<String,ArrayList<ArrayList<NewClass>>>();
ArrayList<ArrayList<NewClass>> bigList = new ArrayList<ArrayList<NewClass>>();
ArrayList<NewClass> nList = new ArrayList<NewClass>();
nList.add(n);
nList.add(n);
bigList.add(nList);
map.put("word", bigList);
System.out.println(map);
}
}
produces
{word=[[1 [2, 3], 1 [2, 3]]]}