File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes HashSet will allow null values? 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 "HashSet will allow null values?" Watch "HashSet will allow null values?" New topic
Author

HashSet will allow null values?

Sakthivel Sabapathy
Greenhorn

Joined: Oct 20, 2000
Posts: 4
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

Joined: Oct 22, 2000
Posts: 17
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

Joined: Oct 20, 2000
Posts: 4
So that means Jamie Jaworskie book that specified statement is wrong. Am i right?
Sarath Lingamarla
Greenhorn

Joined: Jun 12, 2013
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashSet will allow null values?
 
Similar Threads
about Hashset
Question About TreeSet?
null values of collections
Duplicates in Collections-Confused!!
Hashset, Hashtable and Hashmap