Hastable_Dictionary1
A dictionary is an abstract class to map key to values. In Java Dictionary is deprecated and implemented with Map interface.
  • NULL
    • in Java Hashtable doest not permit NULL value
    • HashMap NULL is permitted
    • LinkedHasMap NULL is permitted
  • Synchronization:
    • HasTable : yes
    • HasMap : NO
    • LinkedHasMap : NO
  • Order
    • LinkedHasMap yes
Compared with Java
 

// Namespace Declaration
//File location : C:\BareBone_CSharp\Source_Code\Template
using System;
//csc test_hastable1.cs
using System.Collections;
// Program start class
namespace test_hastable1
{

class CsharpTemplate
{
// Main begins program execution.
public static void Main(string[] str1)
{
Hashtable hashtable = new Hashtable();
hashtable[1] = "Jan";
hashtable[2] = "Feb";
hashtable[3] = "Mar";

foreach (DictionaryEntry entry in hashtable)
{
Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
}
}
}
}
//
}

in Java Dictionary collection is deprecated with MAP

//C:\BareBone_CSharp\Source_Code\Template
import java.util.Hashtable;
import java.util.Enumeration;//enumeration
import java.util.Iterator;
import java.util.Collection;
import java.util.*;
//javac Test_HashMap1.java
public class Test_HashMap1{

public static void main(String[] args) {
// TODO Auto-generated method stub

//----
Map <String, String>dict1 = new HashMap();
dict1.put("key1", "Jan");
dict1.put("key2", "Feb");
dict1.put("key3", "Mar");
dict1.put("key4", "Apr");
int n1 = dict1.size();
Collection<String> col1 = dict1.keySet();
Iterator<String> it1 = col1.iterator();
Collection<String> col2 = dict1.values();
Iterator<String> it2 = col2.iterator();
//
for(int i=0; i< n1; i++)
{
String str1 = (String) it1.next();
System.out.print(str1 + " ");
String str2 = (String) it2.next();
System.out.print(str2 + " " + " ::");
}

}
}// end of Test_HashMap1