2

I want to filter an arraylist indexes and filter a doc based on the docid I provide.

The below code works for 0th index but cant search the whole list and findout the docid

  var results =
this._items?.userItems?.filter { it -> it.requests.get(0).doc == docid }

Kindly suggest the better way of doing It.

Any help is highly appreciated

Thanks

1 Answer 1

3

Assuming that you want to keep only the userItems that have any request with the given docid, you can use it.requests.any { request -> request.doc == docid }.

From the documentation (see the overload that takes in a predicate):

Returns true if at least one entry matches the given predicate.

If you want to get all the requests with the given docid instead, you can use: userItems.flatMap { it.requests }.filter { it.doc == docid }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.