fork download
  1. public class MapToListAndSet {
  2.  
  3. // Method to convert Map values to a List
  4. public static List<String> mapToList(Map<Integer, String> inputMap) {
  5. List<String> resultList = new List<String>();
  6. resultList.addAll(inputMap.values());
  7. return resultList;
  8. }
  9.  
  10. // Method to convert Map keys to a Set
  11. public static Set<Integer> mapToSet(Map<Integer, String> inputMap) {
  12. Set<Integer> resultSet = new Set<Integer>();
  13. resultSet.addAll(inputMap.keySet());
  14. return resultSet;
  15. }
  16.  
  17. // Method to test the functionality of mapToList and mapToSet
  18. public static void testMethods() {
  19. // Create a sample map
  20. Map<Integer, String> sampleMap = new Map<Integer, String>();
  21. sampleMap.put(1, 'Apple');
  22. sampleMap.put(2, 'Banana');
  23. sampleMap.put(3, 'Cherry');
  24.  
  25. // Get List of values
  26. List<String> resultList = mapToList(sampleMap);
  27. System.debug('List of Map Values: ' + resultList);
  28.  
  29. // Get Set of keys
  30. Set<Integer> resultSet = mapToSet(sampleMap);
  31. System.debug('Set of Map Keys: ' + resultSet);
  32. }
  33. }
Success #stdin #stdout #stderr 0.01s 8864KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #MapToListAndSet
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #MapToListAndSet (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
stderr
./prog:3: parse error, expected '}'