I decided to use a simple example of a creation of HashMap and store in it the names of the seasons and the related adjectives.
First code snippet is a Java 1.4 code.
class HashMapJavaShow {
public static void main(String[] args) {
// creation of the hashmap
HashMap<String, String> seasons = new HashMap<String, String>();
// insertion of data, key => value
// in this example we take the name of the season as key
// and the related adjective as value
seasons.put("spring", "vernal");
seasons.put("summer", "estival");
seasons.put("automn", "autumnal");
seasons.put("winter", "hibernal");
// before 1.5 we were forced to use an iterator
Iterator iter = seasons.iterator();
// loop until the iterator has not more element
while(iter.hasNext()){
// retrieve the current element and display it
// using its default method toString()
System.out.println(iter.next());
}
}
}