Skip to Main Content

Java Programming

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!

Date Object as a key in Hash table

J4JavaAug 29 2013 — edited Aug 30 2013

Hi,

I'm having a hash table with date object as key , the purpose is I can pick the value which is available in given date range. Consider the below example

Coffee Powder[Code CODE1] - Effective 21-Jan & Expiry 20-Jun

Coffee Powder[Code CODE1] - Effective 22-Jun & Expiry 30-Dec

Meat[Code CODE2] - Effective 21 - Jan & Expiry 1 - Feb

Meat[Code CODE2] - Effective 2 Feb &  Expiry 6 - Feb

Currently I'm using the following hashtable & it has the structure Key - Code & Value [ List of objects] ]

CODE1- List[ Coffe Powder - 21 Jan - 20 Jun , Coffee Powder - 22 Jun - 30 Dec ]

CODE2- List[ Meat - 21 Jan - 01 Feb, Meat - 02 Feb - 06 Feb ]

To get the value which is valid for the given date , i need to get the list by passing the code & iterate the list to get the best matched value.

Example , if I want the Coffee Powder Information which is valid on 1 Feb. I need to get pass the code ( CODE 1 ) which will returns the list of objects. After we need to iterate the list to get the best match.

Instead of iteration , is there any way to maintain the hashtable & get the results quicker..?

Thx.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2013
Added on Aug 29 2013
2 comments
570 views