Answer the question
In order to leave comments, you need to log in
Finding ArrayList element in RecyclerView?
I have a collection, let's say:
id - element id
message - message
parent - parent, can contain 0 or element id
The task is to find the position of the parent to get the data if parent > 0
What I came up with at the moment:
1)indexOf
There is a method indexOf which just performs the search I need, but I just didn’t understand how to apply (and is it even possible?) indexOf in the ArrayList collection. Of course, you can create another ArrayList object and search it and then use the resulting index to get data from the main collection.
2) Loop
Loop through the entire collection and find the desired index
Tell me how to implement it more correctly
Answer the question
In order to leave comments, you need to log in
um, do I understand correctly that the parent is in the same collection as the element, and your task is to find this parent by the element's parent? What prevents you from running through the collection again in search of the parent? indexOf does just that. Well, only naturally the search for parents for n elements will have quadratic complexity
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question