This post originated from an RSS feed registered with Java Buzz
by Javin Paul.
Original Post: 10 Examples of HashMap in Java - Programming Tutorial
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
HashMap in Java is one of the most popular Collection class among Java
programmers. After by article How
HashMap works in Java, which describes theory part of Java HashMap ,I
thought to share, How to use HashMap in Java with fundamental HashMap examples,
but couldn't do that and it was slipped. HashMap is a a data structure, based
on hashing, which allows you to store object as key value pair, advantage of
using HashMap is that, you can retrieve object on constant time i.e. O(1), if you know
the key. HashMap implements Map interface and supports Generics
from Java 1.5 release, which makes it type safe. There are couple of more
Collections, which provides similar functionalities like HashMap, which can
also be used to store key value pair. Hashtable is one of
them, but Hashtable is synchronized and performs poor in single threaded
environment. See Hashtable
vs HashMap for complete differences between them. Another one, relatively
new is ConcurrentHashMap, which provides better
performance than Hashtable in concurrent environment and
should be preferred. See difference
between ConcurrentHashMap and HashMap for detail differences. In this Java
tutorial, we will see different examples ofHashMap, like adding and removing entries, iterating over Java HashMap,
checking size map, finding if a key or value exists on Map and various other
examples, which we used frequently.