I want to find index no of two,three or more same item in a list
For ex
List 1
Sumit
Varun
Sumit
Ritik
Sumit
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
I want to find index no of two,three or more same item in a list
For ex
List 1
Sumit
Varun
Sumit
Ritik
Sumit
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<>();
while(list.contains(xyz)){
int i = list.indexof(xyz);
inlist.add(i);
list.remove(i);
}
I believe what @Soham_Shah talking is:
And @vknow360 talking about, (using my tiny little bit of JavaScript Knowledge)
@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.
Hmmm yeah i tested and its working… U know We coders never suggest anything without testing
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 @iamwsumit
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
results
thank you all for responsing but I think I have choose the best and simple solution by watermelonice
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.