How to get index no of two same item in a list

I want to find index no of two,three or more same item in a list

For ex

List 1

I want to get sumit’s index in list 2
I have searched on community and finds a post but it doesn’t find index

You can use use a for each umber loop if your list contains two same items and you can set ‘to’ of the for each number loop to lenhht of list, and underneath it put select item list block where index should be number and test the name of whom you want


An amazing workaround:
List< Integer > inlist = new ArrayList<>();
int i = list.indexof(xyz);


I believe what @Soham_Shah talking is:

And @vknow360 talking about, (using my tiny little bit of JavaScript Knowledge)


Yes it is what I was talking about @WatermelonIce

@kumar1334sumit Actually all of the above given solutions have one limitation as we have to check manually that which item is duplicated

i have an onther solution that will work automatically and give solution without manual work

did you even tested it? I don’t think it will work.

Ok, I used a bit of @Zia_Choudhary idea, this method can detect only one duplicated item.

Hmmm yeah i tested and its working… U know We coders never suggest anything without testing :relaxed:

If you add one unique item in the end it will not worked. Because you are lucky that the last one is the duplicated item. And for each item in the list, if it is in the same list then set it to the duplicated item??? What is this?

If i get some free time i’ll post a procedure thar will check all of the duplicated items and then show their respective indexces with their names

Actually I was createing a commplete procedure that can detect every duplicated item in list and show ita index with name… But then i had to go for another work… So i quit and make it like thia… As i mentioned above i’ll post the complete solution too

@WatermelonIce and @Sumit1334
here is the final solution that can select all the duplicated items from a list and then show their respective indexes along with item name automatically with no manual work

Note i made it roughly it can be simplified too but here we have all the blocks


1 Like

thank you all for responsing but I think I have choose the best and simple solution by watermelonice

1 Like

I marked

As solution, because I just did what @Soham_Shah say.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.