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

Value update in hashmap

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

I have a requirement to hold employee information in hashmap with fields like empid, name, salary and fields like FL1, FL2 etc. So I am getting all these informations from database and putting into a hashmap as below

Then I put this map into the list and return back to the calling function. If there are 1200 emp i will have list size as 1200..i.e. 1200 map obj. In course of this process, there are chances that FL1..FL10 etc have some negative values which should be converted back to zero. I could handle that in the while loop when putting into map, but due to some other business logic, i should not convert into ZERO until the while loop finishes.

Now, as the list contains objects and since i have to convert negative values in some fields of the maps to zero..i require to loop again..this will create an introduction of another big loop. Please let me know if you have any other thoughts to meet this scenario.

Thanks in advance.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

I'm not sure what you're asking for here. You basically say "I need to create all these objects, and only after I'm done can I check/change the values in each".

If that is your requirement, then what are you hoping to get from us?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

If storage isn't much of an issue you can store both values, with two keys per value. For example, key FLX (X = 1..10) maps to the modified value and FLX_ORIG (X = 1..10) maps to the original value.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Value update in hashmap
jQuery in Action, 3rd edition