List Contains in Kotlin

Level 277 keystrokes

Checks whether a list contains given elements, using the in operator and contains().

Kotlin code

// A list of the numbers 1 to 5
1val nums = listOf(1, 2, 3, 4, 5)
// x in list checks membership; 3 is in the list, so this prints true
2println(3 in nums)
// in is shorthand for contains(); 6 is not in the list, so this prints false
3println(nums.contains(6))

Output

true
false
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Kotlin code and how often they appear.

  • ,× 4
  • (× 4
  • )× 4
  • .× 1
  • =× 1

More Kotlin examples at level 2

← Kotlin typing practice