開発環境
- macOS Mojave - Apple (OS)
- Windows 10 Pro (OS)
- IntelliJ IDEA CE(Community Edition) (IDE(統合開発環境))
- Kotlin (プログラミング言語)
Head First Kotlin: A Brain-Friendly Guide (Dawn Griffiths(著)、David Griffiths(著)、O'Reilly Media)のChapter 9(collections - Get Organized)、Code Magnets(261)の解答を求めてみる。
コード
fun main() {
var a: MutableList<String> = mutableListOf()
a.add(0, "Zero")
a.add(1, "Two")
a.add(2, "Four")
a.add(3, "Six")
println(a)
if (a.contains("Zero")) a.add("Eight")
a.removeAt(0)
println(a)
if (a.indexOf("Four") != 4) a.add("Ten")
println(a)
println(a)
}入出力結果
[Zero, Two, Four, Six] [Two, Four, Six, Eight] [Two, Four, Six, Eight, Ten] [Two, Four, Six, Eight, Ten] Process finished with exit code 0
0 コメント:
コメントを投稿