Reputation: 5477
I'm trying to fill a list of list List<List<String>>
in Java, but when I print the elements, nothing appears!
my code:
List<String> temp = new ArrayList<>();
for (int z = 0; z < c.POSList.get("V").size(); z++) {
temp.add(c.stemmer(c.POSList.get("V").get(z)).get(0));
temp.addAll(c.ReturnListOFSynoums(c.stemmer(c.POSList.get("V").get(z)).get(0), ""));
System.out.println(temp); // there are elements !
verbsMatrix.add(temp);
temp.clear();
}
for (int s = 0; s < verbsMatrix.size(); s++) {
for (int r = 0; r < verbsMatrix.get(s).size(); r++) {
System.out.print(verbsMatrix.get(s).get(r) + " ");
}
}
Upvotes: 0
Views: 890
Reputation: 4086
You're clearing temp
every time, this is the same instance you just added to verbsMatrix
which you don't re-initialize.
Try declaring temp
inside the for, and don't clear it.
Upvotes: 4