• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashSet will allow null values?

 
Sakthivel Sabapathy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me whether HashSet will allow null value or not?
Because in Jamie Jaworski book described as
"It does not allow the use of null element".
 
anrup kris
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in the API that HashSet permits null values,where as the class HashTable implements a hashtable and maps keys to values.So it does not permit null values
regards
kris
 
Sakthivel Sabapathy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that means Jamie Jaworskie book that specified statement is wrong. Am i right?
 
Sarath Lingamarla
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sakthivel Sabapathy wrote:So that means Jamie Jaworskie book that specified statement is wrong. Am i right?



HashSet allows null value not null values. it allows only 1 null value per 1 HashSet Object

import java.lang.*;
import java.util.*;
public class Set
{
public static void main(String [] args)
{
Set<Integer> s= new HashSet<Integer>();
s.add(new Integer(5));
s.add(null);
s.add(null);
System.out.println(" "+s.size()+"is the set size");
}
}

Output : 2 is the set size
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic