
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java ConcurrentHashMap - clear()
The clear function is used to clear up the mapping between the key value pairs. This way, the ConcurrentHashMap mappings would be cleared.
Syntax
public void clear()
Let us see an example −
Example
import java.util.concurrent.ConcurrentHashMap; import java.util.*; public class Demo{ public static void main(String[] args){ Map<String, String> my_map = new ConcurrentHashMap<String, String>(); my_map.put("This", "35"); my_map.put("is", "78"); my_map.put("sample", "99"); System.out.println("The map contains the below elements " + my_map); my_map.clear(); System.out.println("The elements after the clear function is called on it " + my_map); } }
Output
The map contains the below elements {This=35, is=78, sample=99} The elements after the clear function is called on it {}
A class named Demo contains the main function. Here, a new instance of the Map is created, and elements are added to it using the ‘put’ function. The elemnts are displayed and next, the map is cleared. Now, the map won’t contain anything and this can be seen when the map is displayed again.
- Related Articles
- Difference between HashTable and ConcurrentHashMap in Java
- Difference between HashMap and ConcurrentHashMap in Java
- Difference between HashMap and ConcurrentHashMap
- Java IdentityHashMap clear() method
- Clear LinkedList in Java
- Clear an ArrayList in Java
- NavigableMap clear() Method in Java
- ArrayBlockingQueue clear() Method in Java
- The clear() method of CopyOnWriteArrayListin Java
- How to clear screen using Java?
- Java Program to Clear the StringBuffer
- The clear() method of AbstractSequentialList in Java
- The clear() method of Java AbstractCollection class
- Clear a bit in a BigInteger in Java
- The clear() method of AbstractList class in Java

Advertisements