diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.1.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.1.kt index 2800fbc61..8839c4cb7 100644 --- a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.1.kt +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.1.kt @@ -1,7 +1,8 @@ fun main() { //sampleStart - // Creates an Array with values ["0", "1", "4", "9", "16"] - val asc = Array(5) { i -> (i * i).toString() } - asc.forEach { println(it) } + // Creates an array with values [1, 2, 3] + val simpleArray = arrayOf(1, 2, 3) + println(simpleArray.joinToString()) + // 1, 2, 3 //sampleEnd } \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.10.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.10.kt new file mode 100644 index 000000000..8cee8c249 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.10.kt @@ -0,0 +1,13 @@ +fun main() { +//sampleStart + val simpleArray = arrayOf("a", "b", "c", "c") + + // Converts to a Set + println(simpleArray.toSet()) + // [a, b, c] + + // Converts to a List + println(simpleArray.toList()) + // [a, b, c, c] +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.11.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.11.kt new file mode 100644 index 000000000..43f623457 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.11.kt @@ -0,0 +1,13 @@ +fun main() { +//sampleStart + val pairArray = arrayOf("apple" to 120, "banana" to 150, "cherry" to 90, "apple" to 140) + + // Converts to a Map + // The keys are fruits and the values are their number of calories + // Note how keys must be unique, so the latest value of "apple" + // overwrites the first + println(pairArray.toMap()) + // {apple=140, banana=150, cherry=90} + +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.12.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.12.kt new file mode 100644 index 000000000..b1cc72d58 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.12.kt @@ -0,0 +1,8 @@ +fun main() { +//sampleStart + // Creates an array of Int of size 5 with values + val exampleArray = IntArray(5) + println(exampleArray.joinToString()) + // 0, 0, 0, 0, 0 +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.13.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.13.kt new file mode 100644 index 000000000..7ab657888 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.13.kt @@ -0,0 +1,11 @@ +fun main() { +//sampleStart + var riversArray = arrayOf("Nile", "Amazon", "Yangtze") + + // Using the += assignment operation creates a new riversArray, + // copies over the original elements and adds "Mississippi" + riversArray += "Mississippi" + println(riversArray.joinToString()) + // Nile, Amazon, Yangtze, Mississippi +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.2.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.2.kt new file mode 100644 index 000000000..cc1cebaec --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.2.kt @@ -0,0 +1,8 @@ +fun main() { +//sampleStart + // Creates an array with values [null, null, null] + val nullArray: Array = arrayOfNulls(3) + println(nullArray.joinToString()) + // null, null, null +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.3.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.3.kt new file mode 100644 index 000000000..ce5fe3536 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.3.kt @@ -0,0 +1,13 @@ +fun main() { +//sampleStart + // Creates an Array that initializes with zeros [0, 0, 0] + val initArray = Array(3) { 0 } + println(initArray.joinToString()) + // 0, 0, 0 + + // Creates an Array with values ["0", "1", "4", "9", "16"] + val asc = Array(5) { i -> (i * i).toString() } + asc.forEach { print(it) } + // 014916 +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.4.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.4.kt new file mode 100644 index 000000000..3541e918f --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.4.kt @@ -0,0 +1,13 @@ +fun main() { +//sampleStart + // Creates a two-dimensional array + val twoDArray = Array(2) { Array(2) { 0 } } + println(twoDArray.contentDeepToString()) + // [[0, 0], [0, 0]] + + // Creates a three-dimensional array + val threeDArray = Array(3) { Array(3) { Array(3) { 0 } } } + println(threeDArray.contentDeepToString()) + // [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]]] +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.5.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.5.kt new file mode 100644 index 000000000..fe29485a4 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.5.kt @@ -0,0 +1,14 @@ +fun main() { +//sampleStart + val simpleArray = arrayOf(1, 2, 3) + val twoDArray = Array(2) { Array(2) { 0 } } + + // Accesses the element and modifies it + simpleArray[0] = 10 + twoDArray[0][0] = 2 + + // Prints the modified element + println(simpleArray[0].toString()) // 10 + println(twoDArray[0][0].toString()) // 2 +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.6.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.6.kt new file mode 100644 index 000000000..1cf2add67 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.6.kt @@ -0,0 +1,11 @@ +fun main() { + val lettersArray = arrayOf("c", "d") + printAllStrings("a", "b", *lettersArray) + // abcd +} + +fun printAllStrings(vararg strings: String) { + for (string in strings) { + print(string) + } +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.7.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.7.kt new file mode 100644 index 000000000..912f2a461 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.7.kt @@ -0,0 +1,16 @@ +fun main() { +//sampleStart + val simpleArray = arrayOf(1, 2, 3) + val anotherArray = arrayOf(1, 2, 3) + + // Compares contents of arrays + println(simpleArray.contentEquals(anotherArray)) + // true + + // Using infix notation, compares contents of arrays after an element + // is changed + simpleArray[0] = 10 + println(simpleArray contentEquals anotherArray) + // false +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.8.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.8.kt new file mode 100644 index 000000000..f5b453c8a --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.8.kt @@ -0,0 +1,9 @@ +fun main() { +//sampleStart + val sumArray = arrayOf(1, 2, 3) + + // Sums array elements + println(sumArray.sum()) + // 6 +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.9.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.9.kt new file mode 100644 index 000000000..1c3d29a5b --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/arrays/23031df00534726bea3f25bea3d46032.9.kt @@ -0,0 +1,13 @@ +fun main() { +//sampleStart + val simpleArray = arrayOf(1, 2, 3) + + // Shuffles elements [3, 2, 1] + simpleArray.shuffle() + println(simpleArray.joinToString()) + + // Shuffles elements again [2, 3, 1] + simpleArray.shuffle() + println(simpleArray.joinToString()) +//sampleEnd +} \ No newline at end of file diff --git a/src/test/resources/test-compile-data/jvm/kotlin-web-site/collections-overview/f42863ed2f6912c75d4cf647a4408652.12.kt b/src/test/resources/test-compile-data/jvm/kotlin-web-site/collections-overview/f42863ed2f6912c75d4cf647a4408652.12.kt new file mode 100644 index 000000000..9a2c77966 --- /dev/null +++ b/src/test/resources/test-compile-data/jvm/kotlin-web-site/collections-overview/f42863ed2f6912c75d4cf647a4408652.12.kt @@ -0,0 +1,14 @@ +fun main() { + val deque = ArrayDeque(listOf(1, 2, 3)) + + deque.addFirst(0) + deque.addLast(4) + println(deque) // [0, 1, 2, 3, 4] + + println(deque.first()) // 0 + println(deque.last()) // 4 + + deque.removeFirst() + deque.removeLast() + println(deque) // [1, 2, 3] +} \ No newline at end of file