This post shows examples of codes to check if certain values exists in a list.
Requirements
IntelliJ
IDEA
Ultimate 2016.3- The
Community Edition
may be enough but we have not tried it.
- The
Kotlin
Version 1.1- Windows 10 Enterprise
Check if String is in a list
[wp_ad_camp_1]
1 2 3 4 5 6 7 8 9 10 11 12 13 | package exercise01 fun main(args: Array<String>) { val aphabetList: List<String> = listOf("A", "B", "C", "D", "E", "F") val findValue: String = "D" val found: Boolean = aphabetList.contains(findValue) println("Found ${findValue} yet? " + found) } |
Outputs:
1 | Found D yet? true |
Check if array of Strings is in a list
[wp_ad_camp_2]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | package exercise01 fun main(args: Array<String>) { val aphabetList: List<String> = listOf("A", "B", "C", "D", "E", "F") val findValues: Array<String> = arrayOf("D", "A") val valList = findValues.toList() val found: Boolean = aphabetList.containsAll(valList) println("Found ${valList} yet? " + found) } |
Outputs:
1 | Found D yet? true |
[wp_ad_camp_3]