This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HashTable  RSS feed

 
Puja S
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Puja S
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anand.
 
Puja S
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anand.
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Puja S
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jay .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!