Array
Array is a built-in data type in the Java language. It is a linear sequence that can quickly access other elements and arrays. Unlike other languages. (Recommended learning: java course)
When you create an array, its capacity is unchanged and cannot be changed during the life cycle. There are also JAVA arrays that can do Boundary checking, if an out-of-bounds phenomenon is found, a RuntimeException error will be reported. Of course, checking the boundary will come at the expense of efficiency.
Collection
JAVA also provides other collections, list, map, and set. When they handle objects, it is as if these objects do not have their own types, but directly return to the roots. For Object, you only need to create a collection, put the object in it, and convert it to your own type when taking it out.
The difference between arrays and sets
1.Arrays declare the type of elements they contain, while sets do not.
2. Arrays are static. An array instance has a fixed size. Once created, the capacity cannot be changed. Collections can dynamically expand their capacity and change their size dynamically as needed. Collections provide more member methods to meet more needs.
3. Arrays can only be stored in one type (basic type/reference type), and collections can be stored in different types (the type added when generics are not added is Object).
4. Array is a built-in data type in the Java language. It is arranged linearly and has the fastest execution efficiency or type checking.
The above is the detailed content of The difference between java collections and arrays. For more information, please follow other related articles on the PHP Chinese website!