Entry interface

In this article, we will discuss Entry interface (i.e.; Map.Entry) with all its important methods in detail

Entry is the inner interface defined inside Map interface and contains important methods to operate of only Map entries (or key-value pairs)

 

Entry interface:

  • Entry interface is defined inside Map interface (i.e.; inner interface)
  • To access Entry interface, we have to go through Map interface only i.e.; Map.Entry
  • Reason: Each key-value pair of map is known as Entry. So, to perform Entry specific operations, there should exist Map
  • There is no need of Entry interface without existence of Map interface
  • It is also referred as collection of entry objects
  • Entry interface contains several methods to perform various operations on Map entries
  • Present in java.util package inside java.util.Map interface

025-map-interace-in-java

Source: Team BenchResources.Net

 

Entry interface methods:

Entry methods Description
Object getKey(); returns key from invoking Map.Entry object
Object getValue(); returns value from invoking Map.Entry object
Object setValue(Object val); set the specified value into invoking Map.Entry object

 

Factors to consider while discussing any collection class

We should consider below factors while discussing any implementation class of collection framework or for that matter Map interface,

  • Underlying data structure
  • Duplicates are allowed or Not
  • Insertion order is maintained or Not
  • Whether NULL insertion is possible or Not
  • If possible, how many NULL values can be inserted
  • Whether collection class provide sorting, by default
  • Is there any way to apply customized sorting
  • Performance, while dealing with retrieval or manipulation (addition/deletion)
  • By default, all methods are synchronized or Not

 

References:

https://docs.oracle.com/javase/tutorial/collections/intro/
https://docs.oracle.com/javase/tutorial/collections/interfaces/collection.html
https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html
https://docs.oracle.com/javase/7/docs/api/java/util/Map.html
https://docs.oracle.com/javase/7/docs/api/java/util/Map.Entry.html
https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html

 

Happy Coding !!
Happy Learning !!

HashMap class
Map interface