Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

plz explain the difference........  RSS feed

 
arivu mathi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;
public class Test2{
public static void main(String a[]){
Map s = new Hashtable();
s.put(null,null);
System.out.println(s);
}
}
What is the output?

NullPointerException



import java.util.*;
public class Test3{
public static void main(String a[]){
Map s = new WeakHashMap(10);
s.put(null,null);
System.out.println(s);
}
}

What is the output?

[null = null]
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable API:
The Hashtable class implements a hashtable, which maps keys to values. Any non-null object can be used as a key or as a value.

WeakHashMap API:
Both null values and the null key are supported. This class has performance characteristics similar to those of the HashMap class, and has the same efficiency parameters of initial capacity and load factor.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!