Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.HashSet; import java.util.Map; public class Main { public static <V> HashSet<V> getHashSet(final Map<?, ? extends V> map, final Collection<? extends Object> keys) { final HashSet<V> result = new HashSet<V>(); get(map, keys, result); return result; } public static <V> HashSet<V> getHashSet(final Map<?, ? extends V> map, final Object... keys) { final HashSet<V> result = new HashSet<V>(); get(map, result, keys); return result; } public static <V> void get(final Map<?, ? extends V> map, final Collection<? extends Object> keys, final Collection<? super V> values) { for (final Object key : keys) { if (!map.containsKey(key)) { continue; } final V value = map.get(key); values.add(value); } } public static <V> void get(final Map<?, ? extends V> map, final Collection<? super V> values, final Object... keys) { for (final Object key2 : keys) { final Object key = key2; if (!map.containsKey(key)) { continue; } final V value = map.get(key); values.add(value); } } }