|
Home
Collections intro
Lists
Maps
Sets
Which collection class?
Sorting
Hashing
Advanced
Video lecture: hash tables
Bloom filters
Collections in Java
A collection is a general term that means something like "a bunch of objects
stored in a structured manner". Java has various standard collection classes and using collections in
Java allows you to organise data in memory in various convenient ways. Examples might include:
- a simple list of strings;
- a mapping or association of strings to strings (e.g. country names to the names of their capitals);
- a list that imposes some constraint, e.g. keeping strings in alphabetical order, or not allowing duplicates in the list.
The Java Collections Framework— often called simply (Java) Collections—
is a library of classes that implement these and various other data structures.
The collections framework also provides utility methods to perform functions
such as sorting a list of data.
How to start learning about and using Java collections
There are a couple of ways to approach collections in Java, covered by the
collections tutorials in the rest of this section:
- if you just need a collection of "standard" objects (boring old Strings,
Numbers etc provided by the Java class libraries),
then you can take a fairly practical approach and start using
the standard collections classes without worrying too much about how they work– we'll take a practical look at
lists, sets and maps.
- If you're more or less familiar with what collections are, but are having trouble deciding
which class to use, see the section on How to choose
which Java collection class to use.
- if you need to store instances of your own class in some types of collection,
then you will generally need to understand a little bit (but not all
the details) about how they work, in particular how HashMaps work
via the technique of hashing– however,
you may wish to consult this site's hash function guidelines
if you don't want to get too bogged down in the theory;
- in some cases, you may need to have a fuller understanding about how collection classes
work in order to make decisions relating to performance.
Advanced use of hashing techniques
More advanced readers may wish to take a look at the section on
advanced use of hash codes. In this section,
we see how to exploit some statistical properties of hash codes
to reduce the amount of memory needed to perform certain tasks, notably
duplicate elimination.
What do you think of this article? Did it help you? Found a mistake? Feedback and suggestions here
Written by Neil Coffey. Copyright © Javamex UK 2011. All rights reserved.
If you have any feedback on the Java collections tutorials in this section or about the content of this
site in general, please leave a message on the Javamex forum.
|