Using Android Studio 3.3 Kotlin REPL
val squares = IntArray(5) { it+3 }
println(squares)
prints the type/address of the array instead of the contents.
Is there a package that can always get imported in AS, to dump out the array/collection contents instead?
Please, try to check the online documentation before asking questions.
This is what you are looking for: contentToString - Kotlin Programming Language
1 Like
Just confusing because arrays should behave like lists and sets when using println()
.
E.g. Prints the data.
val aSet: Set<Int> = setOf(1,2,3,4,4)
println(aSet)
Why the difference? Are arrays not collections?
Again, I think these are some basic Java questions you are asking.
For anything that is not a primitive (byte
, int
, float
,…), calling toString
on them returns type@hashcode by default, however all the collections in the Java Collections Framework (List
, Set
, Map
,…) override the Object.toString()
method to return its content.
I tried to explain it the best I could, also there is this SO thread you can check: Why does the toString method in java not seem to work for an array - Stack Overflow
1 Like
Arrays are not collections.
2 Likes