- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove all values from Java LinkedHashMap
Use the clear() method to remove all the values from LinkedHashMap in Java.
Create a LinkedHashMap and add some elements −
LinkedHashMap<String,String> l = new LinkedHashMap<String,String>(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad");
Now, let us remove all the values −
l.clear();
The following is an example to remove all values from LinkedHashMap −
Example
import java.util.*; public class Demo { public static void main(String[] args) { LinkedHashMap<String,String> l = new LinkedHashMap<String,String>(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad"); System.out.println("LinkedHashMap elements...
"+l); l.clear(); System.out.println("
LinkedHashMap elements now...
"+l); } }
Output
LinkedHashMap elements... {1=Jack, 2=Tom, 3=Jimmy, 4=Morgan, 5=Tim, 6=Brad} LinkedHashMap elements now... {}
- Related Articles
- Remove a value from Java LinkedHashMap
- Remove all values from TreeMap in Java
- Remove all values from HashMap in Java
- Iterate through the values of Java LinkedHashMap in Java
- Remove all elements from Java NavigableMap
- Remove all elements from Java LinkedHashSet
- Sort LinkedHashMap by values using Comparable Interface in Java
- Remove all elements from TreeSet in Java
- Remove all elements from a HashSet in Java
- Remove all elements from the ArrayList in Java
- How to remove all whitespace from String in Java?
- Java Program to Remove All Whitespaces from a String
- Java Program to remove all elements from a set in Java
- Java Program to remove all white spaces from a String.
- Get Size of Java LinkedHashMap

Advertisements