Shashank
Shashank

Reputation: 435

what does Map.Node<K,V> class in java?

I have seen a static nested classes Node and Entry in all Java Collection Interfaces, i want to know that what is the use of these classes and how can i use Them directly?

Upvotes: 0

Views: 1862

Answers (2)

Shashank
Shashank

Reputation: 435

Result of javap tool on Hashmap$Node Class

Node class is also implementing the Entry interface present in Map as well as Hashmap has Static nested Entry Class too. May Be the Docs on oracle was not Updated with the changes the made in Jdk.

"**Hashmap$Node Class**"

Upvotes: 0

Priyansh Goel
Priyansh Goel

Reputation: 2660

Map.Entry is a key and its value combined into one class. The allows you to iterate over Map.entrySet() without iterating over Keyset first.

for example : If mp is a Map

for (Map.Entry<String, String> entry : mp.entrySet())
{
  System.out.println(entry.getKey() + " " + entry.getValue());
}

I don't see Node as a nested class in the docs.

Upvotes: 2

Related Questions