1

I have an entity

 data class Account (accountId, username, password, active, date...)

Now i have a list of accounts and i want to get the accountId of the account that has active = 1 (The specifications of the app ensures that there is only one account with active = 1) I tried to map the accounts with active = 1 and then i should get the accountId of the only one returned...

 val activeId = accounts.map { accountDto -> accountDto.active = 1 }[0].accountId

This should work but it doesn t. How can i do it efficiently??

1
  • what are you getting in return for this query? Commented Mar 17, 2020 at 10:19

2 Answers 2

4

You can use accounts.find { it.active == 1 }?.accountId

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

Comments

2

use filter to get the account with active == 1

1 Comment

its true...i had to use filter instead of map. Thnx

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.