Skip to content

Instantly share code, notes, and snippets.

@nathanchen
Created August 15, 2012 05:11
Show Gist options
  • Select an option

  • Save nathanchen/3356208 to your computer and use it in GitHub Desktop.

Select an option

Save nathanchen/3356208 to your computer and use it in GitHub Desktop.
JAVA - entrySet remove&clear
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