Advertisement
redikod

Apex Array Operation Example

Oct 22nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. 1.
  2. Write a program in Apex to count a total number of duplicate elements in an array.
  3.  
  4. String[] inputArr = ['A','B','C','D','A','C','A','B','E','F','H','E','I'];
  5.  
  6. Output will be a map, which will contain Element and the count.
  7.  
  8. 2.
  9. Write a program in Apex to find all unique elements in an array.
  10.  
  11. String[] inputArr = ['A','B','C','D','A','C','A','B','E','F','H','E','I'];
  12.  
  13. Find-out unique element from the given array.
  14.  
  15. 3.
  16. Write a program in apex to find the maximum and minimum element in a Map.
  17. Test data:
  18. Map<String, Integer> inputMap = new Map<String, Integer>{'A' => 10, 'B' => 20, 'C' => 30,'D'=>25,'F'=>9};
  19.  
  20. Find-out maximum and minimum value from the example data input.
  21.  
  22. 4.
  23. Write a program in apex to find the od and even element from a Map. and create two different map for odd and even.
  24.  
  25. Map<String, Integer> inputMap = new Map<String, Integer>{'A' => 10, 'B' => 11, 'C' => 12,'D'=>14,'F'=>16};
  26.  
  27. Output will be two Map, one for odd elements map, another one for even element map.
  28.  
  29. 5.
  30. Write a program in apex to find matching records from two map and create anoter map with matched value from input maps.
  31.  
  32. Map<String, String> nameCodeMap = new Map<String, String>{'PRV' =>'Parvez', 'KSR' => 'Kausar', 'YZ' => 'Yousuf','RZ'=>'Reza','ZKR'=>'Zakir'};
  33.  
  34. Map<String, String> nameDistrictMap = new Map<String, String>{'PRV' =>'Chandpur', 'KSR' => 'Barura', 'YZ' => 'Daudkandi','RZ'=>'Manikganj','ZKR'=>'BBaria'};
  35.  
  36. Map<String, String> namePlatformMap = new Map<String, String>{'PRV' =>'PHP', 'KSR' => 'PHP', 'YZ' => 'Java','RZ'=>'Test','ZKR'=>'Salesforce'};
  37.  
  38. Map<String, String> nameCompanyMap = new Map<String, String>{'PRV' =>'Bangal', 'KSR' => 'Shohoj', 'YZ' => 'Innovitio','RZ'=>'BJIT','ZKR'=>'Arollo'};
  39.  
  40. Cross-check and print list of names for each user.
  41. Example output:
  42. Kausar, KSR, Barura, PHP, Shohoj.
  43. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement