Java Hashed Collections

The Java collections framework contains classes you use to maintain collections of other objects. These collection classes have different performance and ordering properties. See how the HashMap and HashSet Classes allow objects to be added to a collection, removed from a collection, or found in roughly constant time. Discover how to use these classes and what to do to achieve good performance from them.

HashMap and HashSet



The HashMap and HashSet classes provide two different but similar ways to organize a set of objects using the same underlying data structure.

The HashSet class is used to manage a set of objects that have unique values. Passing an object to a HashSet object's add method will add the object to the HashSet unless there is already an object in the HashSet that equals the object passed to the add method. There is also a contains method to find an object in a set and a remove method to remove an object from a set.

The HashMap class organizes objects into pairs. There are two roles in each pair. These roles are key and value. A HashMap object organizes the pairs of objects so that no two pairs have equal keys. This means that, for each key in a HashMap, there is exactly one corresponding value.

The HashMap class has a put method that is passed a key and value pair. If the key is not already in the HashMap, the pair is added to the HashMap. If the key is already present in the HashMap, the given value replaces the previous value associated with the key. There is also a get method that returns the value associated with a given key and a remove method that removes the key-value pair for a given key.

A HashMap is like a HashSet with each object in the set having an associated value. The HashSet class is implemented as a wrapper around HashMap that uses the same object for both the key and value of each object pair.

Read the Rest of this Article at Developer.com

Related Articles
- Enterprise Java Application Architecture and Design
Discover how to combine the Model-View-Controller (MVC) architectural principles with the Java EE platform to derive multitier Java EE application architecture. You will also see how the Java EE design patterns catalog provides guidance and how you can document this architecture using UML notations.
- UML for Object-Oriented Design
- GlassFish ESB V2 for SOA Tooling
- Java Standardization Request 168
- Java Ordered Collections and SortedSet
Regional Articles
- Java Hashed Collections Alabama
- Java Hashed Collections Alaska
- Java Hashed Collections Arizona
- Java Hashed Collections Arkansas
- Java Hashed Collections California
- Java Hashed Collections Colorado
- Java Hashed Collections Connecticut
- Java Hashed Collections DC
- Java Hashed Collections Delaware
- Java Hashed Collections Florida
- Java Hashed Collections Georgia
- Java Hashed Collections Hawaii
- Java Hashed Collections Idaho
- Java Hashed Collections Illinois
- Java Hashed Collections Indiana
- Java Hashed Collections Iowa
- Java Hashed Collections Kansas
- Java Hashed Collections Kentucky
- Java Hashed Collections Louisiana
- Java Hashed Collections Maine
- Java Hashed Collections Maryland
- Java Hashed Collections Massachusetts
- Java Hashed Collections Michigan
- Java Hashed Collections Minnesota
- Java Hashed Collections Mississippi
- Java Hashed Collections Missouri
- Java Hashed Collections Montana
- Java Hashed Collections Nebraska
- Java Hashed Collections Nevada
- Java Hashed Collections New Hampshire
- Java Hashed Collections New Jersey
- Java Hashed Collections New Mexico
- Java Hashed Collections New York
- Java Hashed Collections North Carolina
- Java Hashed Collections North Dakota
- Java Hashed Collections Ohio
- Java Hashed Collections Oklahoma
- Java Hashed Collections Oregon
- Java Hashed Collections Pennsylvania
- Java Hashed Collections Rhode Island
- Java Hashed Collections South Carolina
- Java Hashed Collections South Dakota
- Java Hashed Collections Tennessee
- Java Hashed Collections Texas
- Java Hashed Collections Utah
- Java Hashed Collections Vermont
- Java Hashed Collections Virginia
- Java Hashed Collections Washington
- Java Hashed Collections West Virginia
- Java Hashed Collections Wisconsin
- Java Hashed Collections Wyoming
Related Articles
- Enterprise Java Application Architecture and Design
Discover how to combine the Model-View-Controller (MVC) architectural principles with the Java EE platform to derive multitier Java EE application architecture. You will also see how the Java EE design patterns catalog provides guidance and how you can document this architecture using UML notations.
- UML for Object-Oriented Design
- GlassFish ESB V2 for SOA Tooling
- Java Standardization Request 168
- Java Ordered Collections and SortedSet

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML