Is there any way that I can put a whole Entry
object to a Map
object like:
map.put(entry);
instead of passing a k
Solution if you're using Java Platform SE 8:
SimpleEntry and SimpleImmutableEntry classes implement interface Map.Entry
import java.util.AbstractMap.SimpleEntry;
import java.util.AbstractMap.SimpleImmutableEntry;
List> map = new ArrayList<>();
map.add(new SimpleEntry(key,value));
map.add(new SimpleImmutableEntry(key,value)); // constructs immutable entries for thread-safe operation