• Post Reply Bookmark Topic Watch Topic
  • New Topic

hashtable with Vector  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've created a Hashtable, who's values are Vectors:
>
> Vector a = new Vector();
> a.add("something");
> a.add("somethingelse");
>
> Vector b = new Vector();
> b.add("something1");
> b.add("somethingelse2");
>
> Hashtable ht = new Hashtable();
> ht.put ("key", a);
> ht.put ("anotherkey", b);
>
>
>
> What I want to be able to do is iterate through this Hashtable (in the
JSP),
> pull out a Vector, and iterate through it.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it.

import java.util.*;
public class test {

public static void main(String args[]) {


Vector v = new Vector();
Vector v1 = new Vector();

v.addElement("e");
v.addElement("f");
v.addElement("g");
v.addElement("h");


v1.addElement("e");
v1.addElement("f");
v1.addElement("g");
v1.addElement("h");

HashMap map = new HashMap();

map.put("s",v);
map.put("k",v1);
//map.put("s" ,);

Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String element = (String)it.next();
Vector vtemp = (Vector)map.get(element);
System.out.println("Main " + element);
for (int k = 0 ; k< vtemp.size(); k++)
System.out.println("vedctor elem " + (String)vtemp.elementAt(k));


}



}


}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!