Issue
I am trying to filter the records from list between two numbers (3000 and 3500) and I am facing some issues with filtering and below is my syntax.
val values = 1800
val test = listOf(1818, 2000, 3200, 3250, 3800, 4500)
val filterValue = test.filter { values in 3000..3500 }
println("Test::>$filterValue")
The output should be
Test::> [3200,3250]
Solution
According to the documentation:
in
- is used as an infix operator to check that a value belongs to a range, a collection or another entity that defines the 'contains' method
So, the appropriate answer would be:
listOfValues.filter { it in 3000..3500 }
Notice, that the values are returned inclusive.
Answered By - ivan8m8
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.