import java.util.*; import java.io.*; public class ArraytoHash{ public static void main(String[] args) throws IOException{ String key; String value; ArrayList al1 =new ArrayList(); ArrayList al2 = new ArrayList(); System.out.println("Enter key for the hash table : "); al1 = create(); System.out.println("\n"+"Enter value for the key : "); al2 = create(); Object ia1[] = al1.toArray(); Object ia2[] = al2.toArray(); Hashtable hashTable = new Hashtable (); for(int i = 0; i { key = (ia1[i]).toString(); value = String.valueOf(ia2[i]); hashTable.put(Integer.parseInt(key), value.toString()); } Map map = new TreeMap (hashTable); System.out.println(map); } public static ArrayList create () { ArrayList al = new ArrayList(); try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("How many elements you want to enter to the hash...
The blog will contain all the Technical knowledge I have to share and I welcome & would appreciate others for sharing their knowledge :0)