|
Home
Collections intro
Lists
Maps
Sets
Which collection class?
Sorting
Hashing
Advanced
Video lecture: hash tables
Introduction to Collections in Java
A collection is a general term that means something like "a bunch of objects
stored in a structured manner". 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.
Java provides a number of standard implementations of structures such as lists and maps.
Together, they're sometimes referred to as the Java Collections Framework or
just (Java) Collections. Java also provides utility methods to perform functions
such as sorting a list of data.
There are a couple of ways to approach collections in Java:
- 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 2009. All rights reserved.
|