Biblioteca Java - Blame information for rev 2

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 mihai 1 package colectii.map;
2  
3 import java.util.HashMap;
4 import java.util.Iterator;
5  
6 public class HashMapExample{
7  
8 public static void main(String args[]){
9  
10 HashMap hashMap = new HashMap();
11 //------
12 hashMap.put( "One", new Integer(1) ); // adding value into HashMap
13 hashMap.put( "Two", new Integer(2) );
14 hashMap.put( "Three", new Integer(3) );
15 //------
16 System.out.println("HashMap contains " + hashMap.size() + " key value pair.");
17 //------
18 if( hashMap.containsValue( new Integer(1) ) ){
19         System.out.println("HashMap contains 1 as value");
20 }else{
21         System.out.println("HashMap does not contain 1 as value");
22 }
23 //-------
24 if( hashMap.containsKey("One") ){
25         System.out.println("HashMap contains One as key");
26 }else{
27         System.out.println("HashMap does not contain One as value");
28 }
29 //-------
30 Integer one = (Integer) hashMap.get("One");
31 System.out.println("Value mapped with key \"One\" is " + one);
32 //-------
33 System.out.println("Retriving all keys from the HashMap");
34 Iterator iterator = hashMap.keySet().iterator();
35 while( iterator. hasNext() ){
36         System.out.println( iterator.next() );
37 }
38 //-------
39 System.out.println("Retriving all values from the HashMap");
40 iterator = hashMap.entrySet().iterator();
41 while( iterator. hasNext() ){
42         System.out.println( iterator.next() );
43 }
44 //-------
45 System.out.println( hashMap.remove("One") + " is removed from the HashMap.");
46 }
47  
48 }