The Artima Developer Community
Sponsored Link

Java Answers Forum
Hashtable

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

Hashtable Posted: Dec 9, 2002 6:56 AM
Reply to this message Reply
Advertisement
hello everyone i hope someone can help me
i have the code below which prints out ben twice which is fine. but how would i get the key names of the (st and s ) which should say hello and id.
so i want where the se.equals(st1) part is it gets 2 values but also i want to be able to get the values of there key names aswell
if someone could give me some ideas it would be most grateful
thanks
loftty
import java.io.*;
import java.util.*;
import java.lang.*;


public class Has {
public static void main(String[] args) {

ArrayList arr = new ArrayList();
Hashtable hash = new Hashtable();
String st;
String s;
String st1 = new String("ben");
String st2 = new String("alex");
String st3 = new String("ben");
String st4 = new String("cust");
hash.put(st = "hello", st1);
hash.put("b", st2);
hash.put(s = "id", st3);
hash.put("d", st4);

Enumeration e = hash.elements();
while (e.hasMoreElements()) {
String se = (String)e.nextElement();


if (se.equals(st1)){


System.out.println(se);
}
}
}
}

Topic: Phone Array Previous Topic   Next Topic Topic: Can?t initialize capture device

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use