3:42 pm - Sunday November 18, 3956

Get Size of Java Hashtable Example

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.Hashtable;

class GetSizeOfHashtable{

public static void main(String[] args) {

//creating Hashtable Object

Hashtable ht = new Hashtable();

System.out.println("Size of Hashtable : " + ht.size());

//put() method is used to insert  the elements in a list

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

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

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

System.out.println("Size of Hashtable after addition : " + ht.size());

//remove() method is used to removea element from the table ussig index position

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

System.out.println("Size of Hashtable after removal : " + ht.size());

}

}

Output:

D:\CandidJava\Util\HaashTable>javac  GetSizeOfHashtable.java

Note: GetSizeOfHashtable.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\HashTable>java  GetSizeOfHashtable

Size of Hashtable : 0

Size of Hashtable after addition : 3

Size of Hashtable after removal : 2

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply