Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
ConcurrentHashMap get() Method in Java
Next article icon

ConcurrentHashMap entrySet() method in Java with Examples

Last Updated : 30 Oct, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The entrySet() method of ConcurrentHashMap in Java is used to create a set from the same elements contained in the concurrent hash map. It basically returns a set view of the concurrent hash map or we can create a new set and store the map elements into them. Syntax:
ConcurrentHashMap.entrySet()
Parameters: The method does not take any parameter. Return Value: The method returns a set having same elements as the concurrent hash map. Below programs are used to illustrate the working of entrySet() Method: Program 1: Mapping String Values to Integer Keys. Java
// Java code to illustrate the entrySet() method  import java.util.*; import java.util.concurrent.*;  public class ConcurrentHashMapDemo {     public static void main(String[] args)     {          // Creating an empty ConcurrentHashMap         ConcurrentHashMap<Integer, String>             hash_map = new ConcurrentHashMap<Integer, String>();          // Mapping string values to int keys         hash_map.put(10, "Geeks");         hash_map.put(15, "4");         hash_map.put(20, "Geeks");         hash_map.put(25, "Welcomes");         hash_map.put(30, "You");          // Displaying the HashMap         System.out.println("Initial Mappings are: " + hash_map);          // Using entrySet() to get the set view         System.out.println("The set is: " + hash_map.entrySet());     } } 
Output:
  Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}  The set is: [20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4]  
Program 2: Mapping Integer Values to String Keys. Java
// Java code to illustrate the entrySet() method  import java.util.*; import java.util.concurrent.*;  public class ConcurrentHashMapDemo {     public static void main(String[] args)     {          // Creating an empty ConcurrentHashMap         ConcurrentHashMap<String, Integer>             hash_map = new ConcurrentHashMap<String, Integer>();          // Mapping int values to string keys         hash_map.put("Geeks", 10);         hash_map.put("4", 15);         hash_map.put("Geeks", 20);         hash_map.put("Welcomes", 25);         hash_map.put("You", 30);          // Displaying the HashMap         System.out.println("Initial Mappings are: " + hash_map);          // Using entrySet() to get the set viewa         System.out.println("The set is: " + hash_map.entrySet());     } } 
Output:
  Initial Mappings are: {4=15, Geeks=20, You=30, Welcomes=25}  The set is: [4=15, Geeks=20, You=30, Welcomes=25]  
Note: The same operation can be performed with any type of Mappings with variation and combination of different data types.

Next Article
ConcurrentHashMap get() Method in Java

C

chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java-Functions
  • Java-ConcurrentHashMap
Practice Tags :
  • Java
  • Misc

Similar Reads

    ConcurrentHashMap in Java
    In Java, the ConcurrentHashMap is a thread-safe implementation of the Map interface. It allows multiple threads to read and write data simultaneously, without the need for locking the entire map. Unlike a regular HashMap, which is not thread-safe, ConcurrentHashMap ensures that the operations are th
    15+ min read
    Java ConcurrentHashMap | clear()
    The clear() method in Java's ConcurrentHashMap class is used to remove all the key-value pairs from the map. It has the following signature: The clear() method works in a concurrent environment, which means that it can be called from multiple threads without causing any data race or synchronization
    3 min read
    ConcurrentHashMap compute() method in Java with Examples
    The compute(Key, BiFunction) method of ConcurrentHashMap class is used to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping is found). This method is used to atomically update a value for given key in ConcurrentHashMap.If the remapping funct
    3 min read
    ConcurrentHashMap computeIfAbsent() method in Java with Examples
    The computeIfAbsent(Key, Function) method of ConcurrentHashMap class which attempts to compute its value using the given mapping function for specified key if key is not already associated with a value (or is mapped to null) and enter that computed value in map else null. If mapping function of this
    3 min read
    ConcurrentHashMap contains() method in Java with Examples
    The contains() method of Java.util.ConcurrentHashMap is used to check whether if some key maps into the specified value in this table. It is a legacy method of performing a particular task. The operation is similar to containsValue() Method of ConcurrentHashMap. Syntax: ConcurrentHashMap.contains(Ob
    2 min read
    ConcurrentHashMap containsKey() Method in Java
    The containsKey() method in Java's ConcurrentHashMap class is used to determine whether the map contains a given key. It has the following signature: boolean containsKey(Object key) where: key is the key to be searched for in the map. The containsKey() method works in a concurrent environment, which
    3 min read
    ConcurrentHashMap containsValue() Method in Java
    The containsValue() method in Java's ConcurrentHashMap class is used to determine whether the map contains a given value. It has the following signature: boolean containsValue(Object value) where: value is the value to be searched for in the map.The containsValue() method works in a concurrent envir
    3 min read
    ConcurrentHashMap elements() method in Java with Examples
    The elements() method of ConcurrentHashMap class in Java is used to get the enumeration of the values present in the table. Syntax: Enumeration enu = ConcurrentHashMap.elements() Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the values of the
    2 min read
    ConcurrentHashMap entrySet() method in Java with Examples
    The entrySet() method of ConcurrentHashMap in Java is used to create a set from the same elements contained in the concurrent hash map. It basically returns a set view of the concurrent hash map or we can create a new set and store the map elements into them. Syntax: ConcurrentHashMap.entrySet() Par
    2 min read
    ConcurrentHashMap get() Method in Java
    The get() method in Java's ConcurrentHashMap class is used to retrieve the value associated with a given key. It has the following signature: V get(Object key) where: key is the key whose associated value is to be retrieved.The get() method works in a concurrent environment, which means that it can
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences