Search the element of the ArrayList in RecyclerView?
I have a collection let of the form:
id - the id of the element
message - the message
parent - the parent, can contain 0 or the element id
The task is to find the position of a parent to get the data, if parent > 0
What I came up with at the moment:
1)indexOf
IndexOf is a method that just performs I need search but I just do not understand how to use (and possible?) indexOf in the ArrayList. Of course you can create another ArrayList and search in it and then use the resulting index to get the data from the main collection.
2)Cycle
To iterate over the entire collection cycle and find the correct index
Tell me how to implement it more correctly
1 answer
um, do I understand correctly that the parent is in the same collection as the item, and your task is to find the parent in the parent element? What prevents to go over the collection again in search of a parent? indexOf is exactly what is does. Well, it is only natural to search for the parents of n elements will have quadratic complexity
Find more questions by tags AndroidJava