I need to store some names into a vector and then convert that data into hashtable.The id of the hash table entry will be a serial no. What i did is
import java.io.*;
import java.util.*;
class VecToHash{
public static void main(String [] args){
Vector<String> vec = new Vector<String>();
Hashtable names=new Hashtable();
vec.addElement(new String("name1"));
vec.addElement(new String("name2"));
vec.addElement(new String("name3"));
vec.addElement(new String("name4"));
vec.addElement(new String("name5"));
int VecSize=vec.size();
for (int i=0;i<VecSize;i++){
for (int j=0;j<VecSize;j++){
names.put(("j"), new String(vec.elementAt(i)));
}
Set set=names.keySet();
Iterator itr=set.iterator();
while (itr.hasNext()){
String str=(String) itr.next();
System.out.println(str+":"+names.get(str));}
System.out.println();
}}}
but its not taking the serial number as ID and i also to need to remove duplicates in Hastable. Please help me.
Here is the right code.