Sage-Code Laboratory
index<--

Java Collections

A collection is a container that group multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate structured data.

Collections are packages that have pre-defined interfaces, classes and algorithms to organize and manipulate structured data in memoru. Colection algorithms are usually polimorphic to support a variaty of primitive data types.

Most of the time collections use generics. You can declare a specific collection for you data and then you can use collection API to perform complex operations without duplicating the code and without implementing complex algorithms by yourself.

Interfaces

Collections are too complex and diverse to feet in single inheritance model. To cover this complexity it was necesary to implement a interface hierarchy first. This add improve code reusability.

Collection Interfaces

Interface Hierarchy

Learning tip: First can learn interfaces, almost exactly like classes. Interfaces have the methods required for you to understand then you can use these methods with all kind of classes that you can instantiate. Once you undestend the interfaces you can work with the classes.

Collection Classes

Interfaces for collections are implemented in diverse classes that you can instantiate to create your own collections. Onlu then you can use the methods to manipulate the data.

Collection Interfaces

Interface Hierarchy

Map Collections

Some collections are created in an independent tree. Though iterable these collections have different methods. These collections as very powerful and not to be ignored. Learn this to get more power into your applications.

Java Maps

Map Collections

Read more: Introcution to Collections


Read next: Type Inference