Last active
August 29, 2015 14:14
-
-
Save pcon/2bef4f7fd68335730975 to your computer and use it in GitHub Desktop.
Fun with maps and sets
This file contains hidden or 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
class TestData { | |
public String data; | |
public TestData() {} | |
public TestData(String data) { | |
this.data = data; | |
} | |
} | |
Map<String, TestData> dataMap = new Map<String, TestData>{ | |
'foo' => new TestData('foo'), | |
'bar' => new TestData('bar') | |
}; | |
Set<String> keySet = dataMap.keySet(); | |
System.debug(keySet.size()); // 2 | |
System.debug(dataMap.size()); // 2 | |
keySet.remove('foo'); | |
System.debug(keySet.size()); // 1 | |
System.debug(dataMap.size()); // 1 |
This file contains hidden or 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
class TestData { | |
public String data; | |
public TestData() {} | |
public TestData(String data) { | |
this.data = data; | |
} | |
} | |
Map<String, TestData> dataMap = new Map<String, TestData>{ | |
'foo' => new TestData('foo'), | |
'bar' => new TestData('bar') | |
}; | |
Set<String> keySet = dataMap.keySet().clone(); | |
System.debug(keySet.size()); // 2 | |
System.debug(dataMap.size()); // 2 | |
keySet.remove('foo'); | |
System.debug(keySet.size()); // 1 | |
System.debug(dataMap.size()); // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment