本文介绍了查找重复的值的指数在一个ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含在差异差异指数重复值的ArrayList。
例如 {印,美国,中国,澳大利亚人报,印度,俄罗斯,印}
就像你看到的价值 - 存在于指数 - 0 4 &安培; 6

I have an ArrayList which contains duplicate values at diff diff index.for example {"Indian","American","Chinese","Australian","Indian","Russian","Indian"}as u can see the value - "Indian" exists at index - 0, 4 & 6.

我需要知道所有这些指标,其中存在,并在其中创建的ArrayList。
这里是我的code:

I need to know all these indexes where "Indian" exists and create an arrayList of that.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

在这里,我得到多少次重复的通过获取索引的大小发生(ArrayList中)
但是当我检查的数值。由于该方法在所有指数的一个值:的indexOf()它总是带来第一个值的指数,它在阵列发现

Here I get how many times duplicate occurs by getting the size of indexes(ArrayList)but when I check the values . Its one value at all index since in the method : indexOf() it always brings the index of first value that it finds in the Array.

所以,如果存在重复索引 - 2 5 7
我得到索引的数组大小为 3
但值 {2,2,2,};

So if duplicate exists at index - 2,5,7I get the array size of index as 3.But the values are {2,2,2,};

推荐答案

您需要知道你是在目前,不被发现的地方是第一个指数,指数在数组中为止。为了跟踪这一点,把

You need to know which index in the array you are currently at, not the first index where it is to be found. To keep track of that, put

int i = 0;

在循环之前,并在非常结束循环放

i++;

然后变量 I 告诉你,你已经找到了价值,这样你就可以 I 添加到索引名单。

Then the variable i tells you where you have found the value, so you can add i to the indexes list.

这篇关于查找重复的值的指数在一个ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:25