我試圖顯示arraylist的幾個元素,如果contition爲true。該方法獲取應該在arrayList中找到的String。之後,還有一些其他值包含在List中找到的行後面。 我需要打印thause行的將是1_4_1334-自動....我曾嘗試使用迭代器但沒有運氣。它只是說我無法得到它。在Arraylist中顯示元素組
因此,如果我在尋找2210002_4_1294-Group i應該得到所有包含「Automatic」的字符串,直到達到2210003_4_1295-Group。
任何想法它可以做什麼?
感謝很多:)
MyArrayList:
2210002_4_1294-Group
1_4_1334-Automatic
2_4_1336-Automatic
3_4_1338-Automatic
4_4_1340-Automatic
5_4_1342-Automatic
6_4_1344-Automatic
7_4_1346-Automatic
8_4_1348-Automatic
9_4_1350-Automatic
2210003_4_1295-Group
1_4_1378-Automatic
2_4_1380-Automatic
2210004_4_1296-Group
1_4_1384-Manual
2_4_1386-Manual
方法可能是這樣的:
private void findValueInList(String group){
Iterator<String> iter = arrayList.iterator();
while(iter.hasNext()){
String name = iter.next();
if(name.equals(group)){
here i need to get ValueThatINeed
}
}
}
你的問題不清楚......到底在哪你卡住了?這將有助於,如果你可以提供_actual values_將在列表中的樣本和那些你將打印出來(以及爲什麼)... – Codebender
嗨,想象一下有一個字符串列表。有一個我知道的價值,在價值之後,還有一些我需要得到的價值。但只是傾向於價值觀,不要再去追求。所以在我發現ValueToBeFound之後,我需要得到ValueThatINeed,那就是它。在得到價值觀之後,我可以退出這個循環或者其他的東西。你知道我的意思嗎? :) – Artiom
我也更新了我的帖子,以便更準確:) – Artiom