Issue
I know what is the ?
, !!
, or ==
in kotlin I really confuse the exact difference between them, below I have line of code, what is the difference between both line of code?
users.find { it.id != userId }?.name
users.find { it.id == userId }!!.name
Solution
== operator is used to check whether the contents of 2 variables match example the user.id and it.id in your code.
!= is used when we want to check whether the contents do not match they are opposite to each other.
Update after edit -
Assuming the users
is a list or one of the kotlin collection the first LOC finds the first user from the collection that has same id as userId then if there is such a user ie the ? returns some object then gets the name of same.
The second LOC has a condition that is exactly opposite it finds the first user that does not have the same id and provides its name.
Answered By - Taranmeet Singh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.