aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes HashTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "HashTable" Watch "HashTable" New topic
Author

HashTable

Puja S
Ranch Hand

Joined: Jan 06, 2005
Posts: 51
Hi,

import java.util.*;
public class Test17{
public static void main(String a[]){
Map m = new Hashtable(10,0.75f);
System.out.println(m.size());
}
}

Can anybody explain me,why the output is coming 0 ?

Thanks .
Anand Ko
Ranch Hand

Joined: Dec 03, 2003
Posts: 79
U need to go through the API.

Anyway, size() method returns in the no. of keys in the HashTable. It is just the capacity and loadfactor u have mentioned in the HashTable constructor.


Anand<br />SCJP 1.4, SCWCD 1.4, SCEA 5.0(1/3)
Puja S
Ranch Hand

Joined: Jan 06, 2005
Posts: 51
Thanks Anand.
Puja S
Ranch Hand

Joined: Jan 06, 2005
Posts: 51
Thanks Anand.
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
You have just initialized the Hashtable with initial capacity and loadfactor. There is no key and value in the table, you have to use put method to actually get some size.

m.put(new Test17(), "Hello");
System.out.println(m.size());

Modify your code as above and see the output.
Hope this helps you.


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Puja S
Ranch Hand

Joined: Jan 06, 2005
Posts: 51
Thanks Jay .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashTable