Created
August 15, 2012 05:11
-
-
Save nathanchen/3356208 to your computer and use it in GitHub Desktop.
JAVA - entrySet remove&clear
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
| public V standardRemove(@Nullable Object key) | |
| { | |
| Iterator<Entry<K, V>> entryIterator = entrySet().iterator(); | |
| while(entryIterator.hasNext()) | |
| { | |
| Entry<K, V> entry = entryIterator.next(); | |
| if(Objects.equals(entry.getKey(), key)) | |
| { | |
| V value = entry.getValue(); | |
| entryIterator.remove(); | |
| return value; | |
| } | |
| } | |
| return null; | |
| } | |
| public void standardClear() | |
| { | |
| Iterator<Entry<K, V>> entryIterator = entrySet().iterator(); | |
| while(entryIterator.hasNext()) | |
| { | |
| entryIterator.next(); | |
| entryIterator.remove(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment