0
私は全てのインデックス番号を取得する必要があります。キーワード 'Articles'の一致を取得します&また、 'indexoccncencecounter' 。私の上記のコードは私に間違った出力を与えている値を含むすべてのアイテムのインデックスを取得する
List<String> valueslist = new ArrayList<String>();
valueslist.add("Articles");
valueslist.add("Vals");
valueslist.add("Articles");
valueslist.add("Toast");
String key="Articles";
System.out.println("List contents having values are: "+valueslist);
int ind=0;
int indexoccurencecounter=0;
for (int i=0;i<valueslist.size();i++){
ind=valueslist.indexOf(key);
if (ind>=0){
indexoccurencecounter++;
}
}
System.out.println("Index's of the key "+key+" is: "+ind);
System.out.println("The key specified appears "+indexoccurencecounter+" times in the result links");
私は以下のようになり、出力を期待しています、:
List contents having values are: [Articles, Vals, Articles, Toast]
Index's of the key Articles is: 0,2
The key specified appears 2 times in the result links
パーフェクト!ありがとう... –