I would like to know what the weaknesses of arrays are. I think it’s very useful to know to determine if arrays are the best way to store data in a particular situation or to predict runtime.
Edit 1: Clarification on arrays, as I understand them:
- Not a finite , but a fixed size that is used as serial data containers that are mutable , 1 or more indexes are used to reference a particular data container.
- Data must be of the same type if the type is primitive .
- Data must contain the same data type or a descendant of this type, if type is an object (this is polymorphism ), this kind of transformation narrower and wider , also called covariant transformation.
- All arrays in Java: 1 dimensional arrays .
- Swap elements or a search element with its indexes is fast .
- Adding / removing items is a slow operation since the array is recreated
- Element types are enforced at runtime, this is called a reified array .
- Java array methods are in
java.util.Arrays, and yours do not even contain array management methods such as union and intersection . It is sad that guava libraries are not part of standard Java. - The array of objects is filled with links in the storages where the data is actually located.
- An array of arrays is called a 2-dimensional array .
- 2d arrays of the first array are filled with references to other arrays.
- Other arrays are not stored sequentially.
- Other arrays may vary in element size, this is called ragged - and jagged arrays .
- Java arrays have row order .
- 255, .
.
- , , , .
- , , threadsafe, , - .
- , , , , hashset.contains. strong > , , VMMemoryManager.getIdentityHashCode, .
- Java generics - , Java generic , .
- Java 6 Collections.sort() - ... - x2 .
- , , .
- , , .
-, - , . , , , . , - , .