Ich brauche alle Indexnummern, in denen ich eine Übereinstimmung des Schlüsselwortes "Artikel" bekommen werde & Ich möchte auch den Zähler 'indexoccurencecounter' nur erhöhen, wenn ich eine Übereinstimmung erhalte .Abrufen der Indizes aller Elemente, die einen Wert enthalten
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");
Mein obigen Code ist mir falsche Ausgabe geben, ich erwarte die Ausgabe wie unten zu sein:
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
Perfect! Vielen Dank... –