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 < al1.size(); 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 table : ");
int n = Integer.parseInt(in.readLine());
for ( int i=0; i {
int k = Integer.parseInt (in.readLine());
al.add(k);
}
}
catch(IOException ne)
{
System.exit(1);
}
return al;
}
}
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
for(int i = 0; i < al1.size(); i++)
{
key = (ia1[i]).toString();
value = String.valueOf(ia2[i]);
hashTable.put(Integer.parseInt(key), value.toString());
}
Map
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 table : ");
int n = Integer.parseInt(in.readLine());
for ( int i=0; i
int k = Integer.parseInt (in.readLine());
al.add(k);
}
}
catch(IOException ne)
{
System.exit(1);
}
return al;
}
}
Comments
Post a Comment