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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.