Created
June 10, 2020 05:51
-
-
Save adryanev/d6093dbf458c553b51a53aac0dee6e3c to your computer and use it in GitHub Desktop.
Generic Array pada Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package array_collection | |
import java.util.* | |
class GenericArray { | |
companion object { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
//empty array | |
val emptyArrays = emptyArray<String>() | |
//array with initial value | |
val strings = Array(size = 5, init = { index -> "Item $index" }) | |
println(Arrays.toString(strings)) | |
println (strings.size) | |
//set dan get | |
strings.set(2,"Item diganti") | |
println(strings.get(2)) | |
strings[2] = "Item diganti 2" | |
println(strings[2]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment