Java – Entry interface

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

1. Key points about Map.Entry:

  • Entry is the inner interface defined inside Map interface
  • It contains important methods to operate on Map entries only
  • Map entries is also known as Key-Value pairs

2. Map.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 operation on Map entries
  • Present in java.util package inside java.util.Map interface

Source: Team BenchResources.Net

3. Map.Entry interface methods:

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

4. 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

Related Articles:


Happy Coding !!
Happy Learning !!

Java - HashMap class with examples
Java - Map interface with method details