Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java

What is AbstractMap keyset() in Java?

Abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The keyset() method of the AbstractMap class is used to get the set view of the keys in the abstract map.

Syntax

public Set<K> keySet()

Parameters

The method has no parameters.

Return value

The method returns a set view of the keys in the map.

Example

import java.util.*;
public class Main{
public static void main(String[] args) {
AbstractMap<String, String> abstractMap = new HashMap<>();
abstractMap.put("hello-1", "Educative");
abstractMap.put("hello-2", "edpresso");
abstractMap.put("hello-3", "answers");
System.out.println(abstractMap.keySet());
}
}
Creating and displaying the keySet()

Explanation

  • Line 5: We define an abstract map. The abstract map has the implementation of the hash map.
  • Lines 6–8: We add entries to the map using the put() method.
  • Line 9: We obtain the keys of the map by using the keySet() method and print them.

RELATED TAGS

java

CONTRIBUTOR

Abhilash
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring