KT-22298 Improve docs for Array.copyOf(newSize: Int)
Signed-off-by: Valeriy Zhirnov <neonailol@gmail.com>
This commit is contained in:
committed by
Ilya Gorbunov
parent
df4dcc0f8e
commit
9239de9a02
@@ -17,7 +17,6 @@
|
||||
package samples.collections
|
||||
|
||||
import samples.*
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
@RunWith(Enclosed::class)
|
||||
@@ -76,4 +75,32 @@ class Arrays {
|
||||
}
|
||||
}
|
||||
|
||||
class CopyOfOperations {
|
||||
|
||||
@Sample
|
||||
fun copyOf() {
|
||||
val array = arrayOf("apples", "oranges", "limes")
|
||||
val arrayCopy = array.copyOf()
|
||||
assertPrints(arrayCopy.contentToString(), "[apples, oranges, limes]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun resizingCopyOf() {
|
||||
val array = arrayOf("apples", "oranges", "limes")
|
||||
val arrayCopyPadded = array.copyOf(5)
|
||||
assertPrints(arrayCopyPadded.contentToString(), "[apples, oranges, limes, null, null]")
|
||||
val arrayCopyTruncated = array.copyOf(2)
|
||||
assertPrints(arrayCopyTruncated.contentToString(), "[apples, oranges]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun resizedPrimitiveCopyOf() {
|
||||
val array = intArrayOf(1, 2, 3)
|
||||
val arrayCopyPadded = array.copyOf(5)
|
||||
assertPrints(arrayCopyPadded.contentToString(), "[1, 2, 3, 0, 0]")
|
||||
val arrayCopyTruncated = array.copyOf(2)
|
||||
assertPrints(arrayCopyTruncated.contentToString(), "[1, 2]")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user