Created
September 25, 2017 21:11
-
-
Save pritaunk/20f98848aedd738ff69a6b1828ccd6ef to your computer and use it in GitHub Desktop.
Week4homework
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 WeekFourHomework { | |
public static void setsReview(){ | |
//Your assignment: Play with Sets! | |
// 1. Create a set of Strings and add at least 5 entries | |
Set <string> SetofAccounts = new set <string> (); | |
SetofAccounts.add ('Canon'); | |
SetofAccounts.add ('Google'); | |
SetofAccounts.add ('Apple'); | |
SetofAccounts.add ('Evian'); | |
SetofAccounts.add('Chocolate'); | |
//Use system.debug to print out the size of your set | |
system.debug ('size of set of accounts' +SetofAccounts.size()); | |
//QUESTION : i got a debug 20:06:40:008 USER_DEBUG [17]|DEBUG|size of set of accounts5 , should it not be 4? | |
//considering counting starts at 0? | |
//Add an item to your set that already exists | |
SetofAccounts.add('Chocolate'); | |
system.debug ('size of set of accounts' +SetofAccounts.size()); | |
//Use system.debug to print out the size again, they should be the same! | |
// 2. Bonus Points! Check out the documentation on Sets. Go to the section titled List 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 if the set is empty? Can you clone it? | |
Set <string> setofaccounts2 = setofaccounts.clone(); | |
system.debug('did it clone?' | |
//not sure how to go further... help! | |
} | |
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,string> Accountstatus = new map <string,string> (); | |
accountstatus.put('Canon', 'Customer'); | |
accountstatus.put('Google', 'Prospect'); | |
accountstatus.put('Apple', 'At Risk'); | |
accountstatus.put('Evian', 'Customer'); | |
accountstatus.put('Chocolate', 'Customer'); | |
//Now, in the debug log, print out a list of the values. | |
system.debug('list of accounts with status' +Accountstatus); | |
//couldn't get this to print, it's blank when i run the debug | |
//Can you print out a set of the Keys? | |
set <string> keysonly = accountstatus.keyset(); | |
system.debug('list of keys only' +keysonly); | |
//couldn't get this to print, it's blank when i run the debu | |
// 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> deploymentincludes = new list <string> {'gather requirements', 'build', 'test', 'deploy'}; | |
// 2. Create a second list of Strings and add 5 or more entries to this list. | |
list <string> usertesting = new list <string> {'sandbox logins', 'user to test', 'feedback', 'announcement'}; | |
//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 | |
usertesting.addall(deploymentincludes); | |
//4. Can you now loop through your combined list and print it to the debug log? (Hint: Check the documentation!) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment