[SalesForce] Get Unique keys map and Repeated keys map

Trying to form a two maps. One should contain only unique key and its values and another should have repeated keys and its values.

Name    Position

User1   Developer

User2   Designer

User3   Engineer

User1   Organiser

User2   Admin

First Map should contain only unique Names and its values.

For ex: Unique Map should have only,

User3=>Engineer

Second Map should contain only repeated Names and its values.

For ex: Repeated Map should have,

User1=>Developer, User2=>Designer, User1=>Organiser, User2=>Admin

IMP: Name field must be a key and Position should be a Value in map.

Best Answer

This is not possible, maps do always have unique keys!

If you need multiple values for one key, you could save them in a list and add it to a map with the following structure:

List<String> positionsA = new List<String>{'Manager', 'Admin'};
Map<String, List<String>> positionsByName = new Map<String, List<String>>{'a' => positionsA };