Reputation: 123
How do I iterate over a Vector of Vectors in Java? I tried doing it like in C++ :
Vector<Vector<String>> elements = new Vector<Vector<String>>();
// ...
System.out.print(elements[0][0]);
But obviously that would not work.
Upvotes: 2
Views: 3010
Reputation: 26926
To iterate through all the elements use a code similar to the following:
for (Vector<String> v : elements) {
for (String s : v) {
// Use s as you like
}
}
To access a specific element:
int x = ...
int y = ...
...
String s = elements.get(x).get(y);
Upvotes: 5