The Artima Developer Community
Sponsored Link

Java Answers Forum
delete values from a hastable

1 reply on 1 page. Most recent reply: Dec 9, 2002 12:48 PM by Matt Gerrans

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 1 reply on 1 page
ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

delete values from a hastable Posted: Dec 9, 2002 8:20 AM
Reply to this message Reply
Advertisement
hello everyone i hope someone can help
i have the code below
which tests if any strings are the same to print them out plus there key values
but now i want to able to delete the values and the key names that have already been used
can anyone help please
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; //column names
String s;
String p;
String t;
String st1 = new String("ben");
String st2 = new String("alex"); //table names
String st3 = new String("ben");
String st4 = new String("ben");
hash.put(st = "hello", st1);
hash.put(t = "hehe", st2);
hash.put(s = "id", st3);
hash.put(p = "great", st4);

Enumeration e = hash.keys();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String se = (String) hash.get(key);

if (se.equals(st1)){
System.out.println(se+"\n"+key);
}
if (se.equals(st2)){
System.out.println(se+"\n"+key);
}

}

}
}


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: delete values from a hastable Posted: Dec 9, 2002 12:48 PM
Reply to this message Reply
HashTable has a remove() method that does that.

Flat View: This topic has 1 reply on 1 page
Topic: open a file with the default program Previous Topic   Next Topic Topic: Assignment No. 1

Sponsored Links



Google
  Web Artima.com   

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