This commit is contained in:
parent
f3402dc2d7
commit
490199fd8a
|
@ -44,6 +44,43 @@ fun main(array: Array<String>) {
|
||||||
for (index in items.indices) {
|
for (index in items.indices) {
|
||||||
println(index)
|
println(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 有多少元素
|
||||||
|
val readOnlyShapes = mutableListOf("triangle", "square", "circle")
|
||||||
|
println("readOnlyShapes有:${readOnlyShapes.count()}个元素")
|
||||||
|
println("triangle" in readOnlyShapes)
|
||||||
|
// 添加元素
|
||||||
|
readOnlyShapes.add("YYY")
|
||||||
|
println(readOnlyShapes)
|
||||||
|
// 移出元素
|
||||||
|
readOnlyShapes.remove("triangle")
|
||||||
|
println(readOnlyShapes)
|
||||||
|
|
||||||
|
// Set相关操作
|
||||||
|
val readOnlyFruit = setOf("apple", "banana", "cherry", "cherry")
|
||||||
|
val mutableSetOf = mutableSetOf(readOnlyFruit)
|
||||||
|
println(readOnlyFruit)
|
||||||
|
println(mutableSetOf)
|
||||||
|
println("This set has ${readOnlyFruit.count()} items")
|
||||||
|
|
||||||
|
|
||||||
|
// map 操作
|
||||||
|
val readOnlyJuiceMenu = mapOf("apple" to 100, "kiwi" to 190, "orange" to 100)
|
||||||
|
println(readOnlyJuiceMenu)
|
||||||
|
// {apple=100, kiwi=190, orange=100}
|
||||||
|
|
||||||
|
// Mutable map with explicit type declaration
|
||||||
|
val juiceMenu: MutableMap<String, Int> = mutableMapOf("apple" to 100, "kiwi" to 190, "orange" to 100)
|
||||||
|
println(juiceMenu)
|
||||||
|
|
||||||
|
val SUPPORTED = setOf("HTTP", "HTTPS", "FTP")
|
||||||
|
val requested = "smtp"
|
||||||
|
val isSupported = requested.uppercase() in SUPPORTED // Write your code here
|
||||||
|
println("Support for $requested: $isSupported")
|
||||||
|
|
||||||
|
val number2word = mapOf(1 to "one", 2 to "tow") // Write your code here
|
||||||
|
val n = 2
|
||||||
|
println("$n is spelt as '${number2word[2]}'")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sum(a: Int, b: Int): Int {
|
fun sum(a: Int, b: Int): Int {
|
||||||
|
@ -77,3 +114,4 @@ and ends here. */
|
||||||
|
|
||||||
|
|
||||||
fun maxOf3(a: Int, b: Int) = if (a > b) a else b
|
fun maxOf3(a: Int, b: Int) = if (a > b) a else b
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue