I have an ArrayList that contains duplicate values โโat diff diff index. for example {"Indian","American","Chinese","Australian","Indian","Russian","Indian"} since u can see that the value - "Indian" exists in the index - 0 , 4 and 6 .
I need to know all these indexes where "Indian" exists and create an array. Here is my code:
public void filter(){ categoryArray = Arrays.asList(category); for(String k : category){ //Log.v("filter", filterTerm); if(k.equals(filterTerm.toLowerCase())) { int p = categoryArray.indexOf(k); Log.v("index of categArr", ""+p); String id = Integer.toString(p); indexes.add(id); }// end of if }// end of for
Here I get how many times the duplicate is repeated, getting the size of the indexes (ArrayList) but when I check the values. Its one value in the whole index, as in the: indexOf() method, it always brings the index of the first value that it finds in the array.
So, if a duplicate exists in the index - 2 , 5 , 7 I get the size of the index array as 3 . But the values โโare {2,2,2,};
Ankit source share