//package org.JavaIncloud.java;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class CommonOpetationWithMap 
{
	public static void main(String...JavaInCloud)
	{
		/*create an HashMap(a class implements Map) and assign to a Map as we can not create object for Map interface*/
		Map<Integer, String> dataBases	=	new HashMap<Integer, String>();
		
		//Store some dataBases name to the collection of dataBases object
		dataBases.put(100, "Oracle"); dataBases.put(101, "MySQL");   dataBases.put(102, "Teradata");	  
		dataBases.put(103, "Sybase"); dataBases.put(104, "MongoDB"); dataBases.put(105, "DB2");
		dataBases.put(106, "SQLite"); dataBases.put(107, "Derby");   dataBases.put(108, "SQL-Server");
		//Duplicate key(108) is not allowing simply it'll ignore and over write by Openbase. 
		dataBases.put(108, "Openbase"); 
		//You can duplicate the value(here Derby) for HashMap
		dataBases.put(109,"Derby");   
		
		System.out.println(dataBases);
		//{102=Teradata,103=Sybase,100=Oracle,101=MySQL,108=Openbase,109=Derby,106=SQLite,107=Derby,104=MongoDB,105=DB2}

		//Print the key for value Derby if and only if map is not empty and it contain value Derby otherwise don't go inside
		if(!dataBases.isEmpty() && dataBases.containsValue("Derby"))
		{
			System.out.println("Size of dataBases>>"+dataBases.size());//10
			for (Entry<Integer, String> dataBase : dataBases.entrySet()) 
			{
		        if ("Derby".equals(dataBase.getValue())) 
		        {
		        	int key	=	dataBase.getKey(); //auto unboxing from Integer to int
		            System.out.print(key+" ");
		        }
		        //109 107  
		        //N.B: As with value "Derby" two key is associated hence it is printing 109 and 107
		    }
		}
	}
}
