EnumMap clear() Method in Java with Examples Last Updated : 11 Jul, 2018 Comments Improve Suggest changes Like Article Like Report The Java.util.EnumMap.clear() method in Java is used to remove all the mappings from the map. The method does not delete the map instead it just clears the map of the mappings. Syntax: enum_map.clear() Parameters: This method does not accept any argument. Return Values: This method does not return any value. Below programs illustrate the working of Java.util.EnumMap.clear() method: Program 1: Java // Java program to demonstrate clear() method import java.util.*; // An enum of geeksforgeeks ranking across // Worldwide & in India is created public enum gfg { Global, India } ; class Enum_map { public static void main(String[] args) { EnumMap<gfg, Integer> mp = new EnumMap<gfg, Integer>(gfg.class); // Values are associated in mp mp.put(gfg.Global, 800); mp.put(gfg.India, 72); // Values in mp before removing System.out.println("Values in map before removing " + mp); // Removing the values from mp mp.clear(); // Values in mp after removing System.out.println("Values in map after removing " + mp); } } Output: Values in map before removing {Global=800, India=72} Values in map after removing {} Program 2: Java // Java program to demonstrate clear() method import java.util.*; // An enum of fruits price is created public enum Price_of_Fruits { Orange, Apple, Banana, Pomegranate, Guava } ; class Enum_map { public static void main(String[] args) { EnumMap<Price_of_Fruits, Integer> mp = new EnumMap<Price_of_Fruits, Integer>(Price_of_Fruits.class); // Values are associated in mp mp.put(Price_of_Fruits.Orange, 30); mp.put(Price_of_Fruits.Apple, 50); mp.put(Price_of_Fruits.Banana, 40); mp.put(Price_of_Fruits.Pomegranate, 120); mp.put(Price_of_Fruits.Guava, 20); // Values in mp before removing System.out.println("Values in map before removing " + mp); // Removing the values from mp mp.clear(); // Values in mp after removing System.out.println("Values in map after removing " + mp); } } Output: Values in map before removing {Orange=30, Apple=50, Banana=40, Pomegranate=120, Guava=20} Values in map after removing {} Create Quiz Comment A akash1295 Follow 0 Improve A akash1295 Follow 0 Improve Article Tags : Java Java Programs Java - util package Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like