4:28 pm - Monday December 17, 2018

Java program for LinkedHashMap by using clear()method.

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

import java.util.*;
import java.util.LinkedHashMap;

class LinkedHashMapclear {
public static void main(String args[]) {
// creating LinkedHashMap Object
LinkedHashMap lhm = new LinkedHashMap();
lhm.put(1, "mani");
lhm.put(6, "karthi");
lhm.put(5, "Bala");
lhm.put(4, "Anand");
lhm.put(3, "candid");
// Object obj = lhm.remove(5);/**Removed from key and values*/
System.out.println("Remove of LinkedHashMap are : " + lhm);
// clear() method is used to remove all the elements from the list
lhm.clear();
System.out.println("The clear of LinkedHashMap are : " + lhm);
}
}

/**output

D:\CandidJava\Util\LinkedHashMap>javac LinkedHashMapclear.java

Note: LinkedHashMapclear.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\LinkedHashMap>java LinkedHashMapclear

Remove of LinkedHashMap are : {1=mani, 6=karthi, 5=Bala, 4=Anand, 3=candid}

The clear of LinkedHashMap are : {}

*/

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply