Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set to map question

Status
Not open for further replies.

trium123

IS-IT--Management
Apr 8, 2005
15
0
0
GB
Hi All.
I'm stuck with the correct syntax for inserting the contents of a set<string> into the key section of a map<string, Set<string>>(for now, the values of the map<Set<string>> are empty).
Can anyone help out with this?
Thanks for your time..
Regards
I.
 
What did you do exactly?

Your description looks ambigious:
inserting the contents of a set<string> into the key section of a map<string, Set<string>>
a) The key of a Map is the first part of the pair (key, value)
b) You can use the Set itself as Key or value of a Map, but what do you mean with 'content of a Set'?
That is - if not null, or by chance one String, but normally a lot of them.
But key or value of a Map has to be a single object.
c) You may put every element of a set into a map as key.
After rereading your post for a third time, it seems that this is what you're looking for.
But where's the problem?
Code:
 Set <String> set = new HashSet <String> ();
Map <String, Set<String>> map = new HashMap <String, Set<String>> ();

set.add ("Foo");
set.add ("Bar");
set.add ("Foobar");

for (String s: set)
{
	map.put (s, null);
}

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top