Created
September 22, 2020 17:28
-
-
Save SarahNicewander/14dde28df1316498cee1f25f1567ff2c to your computer and use it in GitHub Desktop.
weekFiveHomework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class WeekFiveHomework { | |
// Remember Sets & Maps?? We did a little practice with Lists in week 2, but we need to make sure we know how to use Sets & Maps as well!! | |
public static void setsReview(){ | |
//Your assignment: Play with Sets! | |
// 1. Create a set of Strings and add at least 5 entries | |
Set<String> stringCustom = new Set<String>(); | |
customString.add('First'); | |
customString('Second'); | |
customString('Third'); | |
customString('Fourth'); | |
customString('Fifth'); | |
//Use System.debug to print out the size of your set | |
system.debug('The size of the set is ' +stringCustom.size()); | |
//Add an item to your set that already exists | |
stringCustom.add('First'); | |
//Use System.debug to print out the size again, they should be the same! | |
system.debug('The size of the set is ' +stringCustom.size()); | |
// 2. Bonus Points! Check out the documentation on Sets. Go to the section titled Set Methods. Pick one of the methods to try out and print the results to the debug log. | |
// Documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_set.htm | |
//Hint: can you print out a boolean that indicates if the set is empty? Can you clone it? | |
} | |
public static void mapsReview () { | |
//Time to get creative! | |
// 1. Create a new Map. You can use whatever primitives/object types you like, as long as they make sense. | |
// Try to add at least 5 Key/value pairs. | |
Map<String, Integer> customMap = new Map<String, Integer>(); | |
customMap.put('First', 1); | |
customMap.put('Second', 2); | |
customMap.putt('Third', 3); | |
customMap.put('Fourth', 4); | |
customMap.put('Fifth', 5); | |
//Now, in the debug log, print out a list of the values. | |
system.debug('My map contains the following' +customMap); | |
//Can you print out a set of the Keys? | |
system.debug('Here is a set of my Keys: ' + customMap.keySet()); | |
// 2. Bonus! Check out the documentation on Maps. Go to the section titled Map Methods. Manipulate the Map using one of the methods defined in the documentation | |
// Documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm | |
// Hint: Can you remove an entry using the key? Can you clear out the map without deleting it? | |
} | |
public static void listsReview() { | |
// 1. Create a list of Strings. Add at least 5 entries to the list, all in one line | |
List<String> stateList = new List<String>{'Ohio', 'Pennsylvania', 'New York', 'North Carolina', 'South Carolina'}; | |
system.debug('My first list contains: ' +stateList); | |
// 2. Create a second list of Strings and add 5 or more entries to this list. | |
List<String> cityList = new List<String>{'Cleveland', 'New Castle', 'Ellicottville', 'Raleigh', 'Charleston'}; | |
system.debug('My Second list contains: ' +cityList); | |
//3. Bonus! Using the documentation on standard List methods from Salesforce, add the items from your first list, to your second list with one command | |
// Documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_list.htm | |
cityList.addAll(stateList); | |
//4. Can you now loop through your combined list and print it to the debug log? (Hint: Check the documentation!) | |
system.debug('My Second list contains: ' +cityList); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment