Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with hash map ! now able to delete key and data from file

843805Jan 24 2006 — edited Feb 2 2006
here i am just skipping the key from the hash map which ever key is matching but when i am removing the key its just stops whr the key is delte ted and do not proceed ahead ...
but if i am commenting //emp.remove(key) then atleast the data is being removed from the file and written again but then the key is not removed from the map . so it still is there in the list .(but in the file the particular map key value is deleted ) but i also want to delete the key from the list how to do it i am not able to get plzz someone help be out on this ! in the output if key is found then deleting is shown but then its just stops does not even go to deleting statement ...
help !!!!

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("so.txt")));
while (keys.hasNext())
{

String key = (String)keys.next();
//String value = (String)emp.get(key);
if(searchName.toLowerCase().equals(key.toLowerCase()))
{
System.out.println("deleting");
dataMatch = ((P)emp.get(key)).pd;
emp.remove(key);
key=(String)keys.next();

System.out.println("deleted");
}
System.out.println("out of for loop");
System.out.println("The elements of HashMap are");
System.out.println(((P)emp.get(key)).saveData());
out.println(((P)emp.get(key)).saveData());

}
out.close();
}catch(Exception f){}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2006
Added on Jan 24 2006
10 comments
360 views