English
Summary
Conclusions
An array has a fixed size, and specialized IntArray and similar types avoid boxing values on the JVM. The contents of arrays are compared with contentEquals, and the rectangular shape of a two-dimensional array must be checked separately. The collection hierarchy separates reading from modification, so functions accept the minimal sufficient interface. A read-only interface does not make an object immutable, and toList() creates a snapshot of the structure but does not copy mutable elements. A list preserves order and duplicates, a set ensures uniqueness by equals and hashCode, and a map holds one value per key. Keys and elements of hash structures must remain stable with respect to equality, and a collection must not be modified during an ordinary traversal. ArrayDeque expresses a stack and a queue, and PriorityQueue selection by a comparator, which must define ties. A structure is chosen by its operations, the data volume, and the ownership contract, and it is tested on an empty set, boundaries, duplicates, and snapshot independence.
Self-check questions
- How does
Array<Int>differ fromIntArray? - How do you compare the contents of two arrays?
- Does
Array<IntArray>guarantee a rectangular shape? - Why does
valnot make a list immutable? - What is the difference between a live view and a snapshot?
- How does
removediffer fromremoveAt? - Why can
subListbe dangerous after the parent changes? - What is the relationship between
equalsandhashCode? - How do you distinguish a missing key from a nullable value?
- When does
getOrPutcall the initial function again? - How do you remove elements during traversal?
- Why is traversing a PriorityQueue not sorting?