Advertisement

06.07.2008 at 11:48AM PDT, ID: 23466365
[x]
Attachment Details

Hashmap design problem

Asked by allelopath in Java Programming Language

Tags:

I need to create a custom class/data structure, probably a hashmap..

Normally one puts to a hashmap like so:
myMap.put(myKey, myThing);

This doesn't quite suite my needs, What I need is to remember the most recent *2* things for any key.
So that if I do:
myMap.put(a, 1);
myMap.put(a, 2);
I can get back either the 1 or the 2.
Furthermore, if I do:
myMap.put(a, 3);
then the 1 would disappear and I'd have available the 2 or the 3.

I'd suggestions on how to implement this, whether with hashmap or if you have a better idea, i'm listening.

Start Free Trial
 
 
[+][-]06.07.2008 at 01:35PM PDT, ID: 21736728

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: Java
Sign Up Now!
Solution Provided By: mbodewes
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.07.2008 at 03:11PM PDT, ID: 21736927

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.07.2008 at 04:20PM PDT, ID: 21737033

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.07.2008 at 05:04PM PDT, ID: 21737095

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628