[英]How to iterate the vector of vectors and get the output in the below scenario?
[英]How to iterate over Vector of Vectors
如何遍歷Java中的向量Vector? 我嘗試像在C ++中那樣做:
Vector<Vector<String>> elements = new Vector<Vector<String>>();
// ...
System.out.print(elements[0][0]);
但是顯然那是行不通的。
要遍歷所有元素,請使用類似於以下內容的代碼:
for (Vector<String> v : elements) {
for (String s : v) {
// Use s as you like
}
}
要訪問特定元素:
int x = ...
int y = ...
...
String s = elements.get(x).get(y);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.