3:30 am - Friday April 19, 2019

LinkedHashMap Example program for Get Size()

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

/**

*@author :CandidJava.com

*@descriptions : This program explain the function and use of size() method

*/

import java.util.LinkedHashMap;

class GetSizeOfLinkedHashMap  {

public static void main(String[] args) {

//creating LinkedHashMap Object

LinkedHashMap lHashMap = new LinkedHashMap();

System.out.println("Size of LinkedHashMap : " + lHashMap.size());

lHashMap.put("1","One");

lHashMap.put("2","Two");

lHashMap.put("3","Three");

//size() method is used to find the elements are in likedHashMap

System.out.println("Size of LinkedHashMap after addition : " + lHashMap.size());

Object obj = lHashMap.remove("2");

System.out.println("Size of LinkedHashMap after removal : " + lHashMap.size());

}

}

output:

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

Note: GetSizeOfLinkedHashMap.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\LinkedHashMap>java GetSizeOfLinkedHashMap

Size of LinkedHashMap : 0

Size of LinkedHashMap after addition : 3

Size of LinkedHashMap after removal : 2

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply