954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Map with array of values??

Hi,
I want to Map a single key to array of values. Is that possible?

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

any1 thr..pls help:(

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

So, you want to do something like:

Map<String, Object[]> objectMap = new TreeMap<String, Object[]>();
Object[] values = new String[] {"A", "B", "C"};
objectMap.put("First3Letters", values);


Is that right? Yes, you can do that.

dononelson
Junior Poster in Training
62 posts since Mar 2010
Reputation Points: 13
Solved Threads: 15
 

Exactly, but, I have read that: "each key can map to at most one value"

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

That means that each key can map to one entry in the map. The map doesn't care what's in the entry (or "value" as it is called). All it knows is that there is an object there (an array is considered an object).

Does that make sense?

dononelson
Junior Poster in Training
62 posts since Mar 2010
Reputation Points: 13
Solved Threads: 15
 

Got it...Thank u:)

javausers
Newbie Poster
21 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: