Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4381692
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:40:53+00:00 2026-05-21T12:40:53+00:00

I have an ArrayList which contains duplicate values at diff diff index. for example

  • 0

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.

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

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.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:40:54+00:00Added an answer on May 21, 2026 at 12:40 pm

    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;
    

    before the loop, and at the very end of the loop put

    i++;
    

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ArrayList which contains cutomer name details. In my JSP I am
I have an object in my Action class which contains an arraylist of objects
I have a class which contains a static collection that can be used across
I have an arraylist that contains items called Room. Each Room has a roomtype
I want to have an ArrayList where it contains HashTables. I create a Hashtable
I created an ArrayList which contains KeyValuePair<string, string> objects. There are ListBoxes which I
I was trying to serialize an ArrayList which contains custom objects. I'm serializing it
I have a huge array list which contains 1000 entries out of which one
Lets say we have a program which contains such classes: public interface AbstractItem {
I have Grid which will render a calendar, and I'm provided with an ArrayList<CalendarEventEntity>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.