Map
HashCode and Equals
public class Car
{
	private String maker;
	private String color;

	public Car(String maker, String color)
	{
		this.maker = maker;
		this.color = color;
	}

	public String toString()
	{
		return maker+": "+color;
	}

	@Override
	public boolean equals(Object c)
	{
		Car temp = (Car) c;
		System.out.println("Equals ...");
		if(maker.equals(temp.maker) && color.equals(temp.color))
			return true;
		else
			return false;
	}

	@Override
	public int hashCode()
	{
		int code = maker.hashCode()+color.hashCode();
		System.out.println("Hash Code: "+code);
		return code;
	}
}
			
import java.util.*;

public class H
{
	public static void main(String args[])
	{
		HashMap<Car, Integer> m = new HashMap<Car, Integer>();

		Car c1 = new Car("Buick", "White");
		Car c2 = new Car("Honda", "Blue");

		//put
		System.out.println("Insert objects into hashMap ...");
		m.put(c1, 1);
		m.put(c2, 2);

		//get
		System.out.println("Access object in hashMap ...");
		System.out.println(m.get(new Car("Buick", "White")));
	}
}
			
HashMap
import java.util.*;

public class H
{
	public static void main(String args[])
	{
		HashMap<String, Integer> m = new HashMap<String, Integer>();

		//put
		m.put("a", 10);
		m.put("b", 20);
		m.put("c", 30);
		m.put("d", 40);

		//get
		System.out.println(m.get("a"));

		//keySet
		Set<String> keys = m.keySet();
		System.out.println(keys);

		//values
		Collection<Integer> values = m.values();
		System.out.println(values);

		//entrySet
		Set<Map.Entry<String, Integer>> entries = m.entrySet();
		for(Map.Entry<String, Integer> e : entries)
			System.out.println(e.getKey()+" "+e.getValue());

		//remove
		m.remove("c");

		//toString
		System.out.println(m);
	}
}
			
LinkedHashMap
import java.util.*;

public class H
{
	public static void main(String args[])
	{
		LinkedHashMap<String, Integer> m = new LinkedHashMap<String, Integer>();

		//put
		m.put("a", 10);
		m.put("b", 20);
		m.put("c", 30);
		m.put("d", 40);

		//get
		System.out.println(m.get("a"));

		//keySet
		Set<String> keys = m.keySet();
		System.out.println(keys);

		//values
		Collection<Integer> values = m.values();
		System.out.println(values);

		//entrySet
		Set<Map.Entry<String, Integer>> entries = m.entrySet();
		for(Map.Entry<String, Integer> e : entries)
			System.out.println(e.getKey()+" "+e.getValue());

		//remove
		m.remove("c");

		//toString
		System.out.println(m);
	}
}
			
TreeMap
import java.util.*;

public class H
{
	public static void main(String args[])
	{
		TreeMap<String, Integer> m = new TreeMap<String, Integer>();

		//put
		m.put("a", 10);
		m.put("b", 20);
		m.put("c", 30);
		m.put("d", 40);

		//firstKey
		System.out.println(m.firstKey());

		//lastKey
		System.out.println(m.lastKey());

		//lowerKey
		System.out.println(m.lowerKey("b"));//a

		//ceilingKey
		System.out.println(m.ceilingKey("b"));//b

		//higherKey
		System.out.println(m.higherKey("b"));//c

		//floorKey
		System.out.println(m.floorKey("b"));//b

		System.out.println(m);

		//headMap
		SortedMap<String, Integer> hMap = m.headMap("b");
		System.out.println(hMap);

		//subMap
		SortedMap<String, Integer> sMap = m.subMap("b", "d");
		System.out.println(sMap);

		//tailMap
		SortedMap<String, Integer> tMap = m.tailMap("b");
		System.out.println(tMap);
	}
}
			
EnumMap
public enum Day
{
	Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday;
}
			
import java.util.*;

public class M
{
	public static void main(String args[])
	{
		EnumMap<Day, String> m = new EnumMap<Day, String>(Day.class);

		//put
		m.put(Day.Monday, "Teaching and Research");
		m.put(Day.Tuesday, "Prepare Course Materials");
		m.put(Day.Wednesday, "Running ...");
		m.put(Day.Thursday, "Meeting ...");

		//get
		System.out.println(m.get(Day.Thursday));

		//toString
		System.out.println(m);
	}
}
			
HashTable
import java.util.*;

public class H
{
	public static void main(String args[])
	{
		Hashtable<String, Integer> grade = new Hashtable<String, Integer>();

		//put
		grade.put("David", 90);
		grade.put("Jeremy", 80);
		grade.put("Antonio", 85);
		grade.put("Ray", 95);

		//get
		System.out.println("Grade for David: "+grade.get("David"));

		//remove
		grade.remove("Antonio");

		//toString
		System.out.println(grade);

		//containsKey
		if(grade.containsKey("Jeremy"))
			System.out.println("Contains the record for Jeremy ...");

		//keySet
		System.out.println(grade.keySet());

		//values
		System.out.println(grade.values());
	}
}
			
Properties
import java.util.*;
import java.io.*;

public class P
{
	public static void main(String args[])
	{
		Properties t = new Properties();

		t.setProperty("color", "blue");
		t.setProperty("maker", "Honda");

		//save properties
		try
		{
			FileOutputStream output = new FileOutputStream("temp.dat");
			t.store(output, "Save Properties");
			output.close();
		}
		catch (IOException ioException)
		{
			ioException.printStackTrace();
		}

		Properties t2 = new Properties();

		//load properties
		try
		{
			FileInputStream input = new FileInputStream("temp.dat");
			t2.load(input);
			input.close();
		}
		catch (IOException ioException)
		{
			ioException.printStackTrace();
		}
		t.list(System.out);
	}
}