File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes delete values  from a hastable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "delete values  from a hastable" Watch "delete values  from a hastable" New topic

delete values from a hastable

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
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
[ December 09, 2002: Message edited by: Michael Ernest ]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
It you want to remove values from the Hashtable while you're looping through it, use an Iterator rather than an Enumeration (as shown in my other post), and use the remove() method of the Iterator. Otherwise you can use the remove(Object) method of Hashtable, where the argument is the key value to be removed. But don't do this while you're looping through the Hashtable - it confuses things.
[ December 09, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Ted Striker

Joined: Dec 08, 2002
Posts: 7
Jim, I posted a HashMap question below and your response to Ben's post has my attention.
I want to take two hashmaps, iterate through each one and remove the hashmap elements that do not match keys. I was recommended an interfact (Coparable) solution but I am trying to make it simpler. How can I iterate through two hashmaps simultaneously while removing elements that don't match? You mention not removing elements while looping. I don't understand. Please see my post re: data structures.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
I replied here.
I agree. Here's the link:
subject: delete values from a hastable
It's not a secret anymore!