SlideShare a Scribd company logo
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 1/8
OVERVIEW PACKAGE CLASS USE TREE DEPRECATED INDEX HELP
Java™ Platform
Standard Ed. 8
PREV CLASS NEXT CLASS FRAMES NO FRAMES ALL CLASSES
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
compact1, compact2, compact3
java.util
Class HashSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.HashSet<E>
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
JobStateReasons, LinkedHashSet
public class HashSet<E>
extends AbstractSet<E>
implements Set<E>, Cloneable, Serializable
This class implements the Set interface, backed by a hash table (actually a HashMap instance). It
makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that
the order will remain constant over time. This class permits the null element.
This class offers constant time performance for the basic operations (add, remove, contains and
size), assuming the hash function disperses the elements properly among the buckets. Iterating
over this set requires time proportional to the sum of the HashSet instance's size (the number of
elements) plus the "capacity" of the backing HashMap instance (the number of buckets). Thus,
it's very important not to set the initial capacity too high (or the load factor too low) if iteration
performance is important.
Note that this implementation is not synchronized. If multiple threads access a hash set
concurrently, and at least one of the threads modifies the set, it must be synchronized
externally. This is typically accomplished by synchronizing on some object that naturally
encapsulates the set. If no such object exists, the set should be "wrapped" using the
Collections.synchronizedSet method. This is best done at creation time, to prevent
accidental unsynchronized access to the set:
Set s = Collections.synchronizedSet(new HashSet(...));
The iterators returned by this class's iterator method are fail-fast: if the set is modified at any
time after the iterator is created, in any way except through the iterator's own remove method,
the Iterator throws a ConcurrentModificationException. Thus, in the face of concurrent
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 2/8
modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-
deterministic behavior at an undetermined time in the future.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking,
impossible to make any hard guarantees in the presence of unsynchronized concurrent
modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort
basis. Therefore, it would be wrong to write a program that depended on this exception for its
correctness: the fail-fast behavior of iterators should be used only to detect bugs.
This class is a member of the Java Collections Framework.
Since:
1.2
See Also:
Collection, Set, TreeSet, HashMap, Serialized Form
Constructor Summary
Constructor and Description
HashSet()
Constructs a new, empty set; the backing HashMap instance has default initial capacity
(16) and load factor (0.75).
HashSet(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection.
HashSet(int initialCapacity)
Constructs a new, empty set; the backing HashMap instance has the specified initial
capacity and default load factor (0.75).
HashSet(int initialCapacity, float loadFactor)
Constructs a new, empty set; the backing HashMap instance has the specified initial
capacity and the specified load factor.
Method Summary
Modifier and Type Method and Description
boolean add(E e)
Adds the specified element to this set if it is not already present.
void clear()
Removes all of the elements from this set.
Object clone()
Constructors
All Methods Instance Methods Concrete Methods
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 3/8
Returns a shallow copy of this HashSet instance: the elements
themselves are not cloned.
boolean contains(Object o)
Returns true if this set contains the specified element.
boolean isEmpty()
Returns true if this set contains no elements.
Iterator<E> iterator()
Returns an iterator over the elements in this set.
boolean remove(Object o)
Removes the specified element from this set if it is present.
int size()
Returns the number of elements in this set (its cardinality).
Spliterator<E> spliterator()
Creates a late-binding and fail-fast Spliterator over the
elements in this set.
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
Methods inherited from interface java.lang.Iterable
forEach
Constructor Detail
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 4/8
HashSet
public HashSet()
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16)
and load factor (0.75).
HashSet
public HashSet(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection. The HashMap is
created with default load factor (0.75) and an initial capacity sufficient to contain the
elements in the specified collection.
Parameters:
c - the collection whose elements are to be placed into this set
Throws:
NullPointerException - if the specified collection is null
HashSet
public HashSet(int initialCapacity,
float loadFactor)
Constructs a new, empty set; the backing HashMap instance has the specified initial
capacity and the specified load factor.
Parameters:
initialCapacity - the initial capacity of the hash map
loadFactor - the load factor of the hash map
Throws:
IllegalArgumentException - if the initial capacity is less than zero, or if
the load factor is nonpositive
HashSet
public HashSet(int initialCapacity)
Constructs a new, empty set; the backing HashMap instance has the specified initial
capacity and default load factor (0.75).
Parameters:
initialCapacity - the initial capacity of the hash table
Throws:
IllegalArgumentException - if the initial capacity is less than zero
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 5/8
Method Detail
iterator
public Iterator<E> iterator()
Returns an iterator over the elements in this set. The elements are returned in no
particular order.
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Specified by:
iterator in class AbstractCollection<E>
Returns:
an Iterator over the elements in this set
See Also:
ConcurrentModificationException
size
public int size()
Returns the number of elements in this set (its cardinality).
Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>
Specified by:
size in class AbstractCollection<E>
Returns:
the number of elements in this set (its cardinality)
isEmpty
public boolean isEmpty()
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 6/8
Returns true if this set contains no elements.
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>
Overrides:
isEmpty in class AbstractCollection<E>
Returns:
true if this set contains no elements
contains
public boolean contains(Object o)
Returns true if this set contains the specified element. More formally, returns true if and
only if this set contains an element e such that (o==null ? e==null : o.equals(e)).
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>
Overrides:
contains in class AbstractCollection<E>
Parameters:
o - element whose presence in this set is to be tested
Returns:
true if this set contains the specified element
add
public boolean add(E e)
Adds the specified element to this set if it is not already present. More formally, adds the
specified element e to this set if this set contains no element e2 such that
(e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call
leaves the set unchanged and returns false.
Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class AbstractCollection<E>
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 7/8
Parameters:
e - element to be added to this set
Returns:
true if this set did not already contain the specified element
remove
public boolean remove(Object o)
Removes the specified element from this set if it is present. More formally, removes an
element e such that (o==null ? e==null : o.equals(e)), if this set contains such an
element. Returns true if this set contained the element (or equivalently, if this set
changed as a result of the call). (This set will not contain the element once the call
returns.)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>
Overrides:
remove in class AbstractCollection<E>
Parameters:
o - object to be removed from this set, if present
Returns:
true if the set contained the specified element
clear
public void clear()
Removes all of the elements from this set. The set will be empty after this call returns.
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface Set<E>
Overrides:
clear in class AbstractCollection<E>
clone
public Object clone()
Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.
8/30/2016 HashSet (Java Platform SE 8 )
https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 8/8
OVERVIEW PACKAGE CLASS USE TREE DEPRECATED INDEX HELP
Java™ Platform
Standard Ed. 8
PREV CLASS NEXT CLASS FRAMES NO FRAMES ALL CLASSES
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation
contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms,
workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see
the documentation redistribution policy.
Overrides:
clone in class Object
Returns:
a shallow copy of this set
See Also:
Cloneable
spliterator
public Spliterator<E> spliterator()
Creates a late-binding and fail-fast Spliterator over the elements in this set.
The Spliterator reports Spliterator.SIZED and Spliterator.DISTINCT. Overriding
implementations should document the reporting of additional characteristic values.
Specified by:
spliterator in interface Iterable<E>
Specified by:
spliterator in interface Collection<E>
Specified by:
spliterator in interface Set<E>
Returns:
a Spliterator over the elements in this set
Since:
1.8

More Related Content

What's hot

Java collections notes
Java collections notesJava collections notes
Java collections notes
Surendar Meesala
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
Java.util
Java.utilJava.util
Java.util
Ramakrishna kapa
 
java collections
java collectionsjava collections
java collections
javeed_mhd
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
Prof. Erwin Globio
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google Collections
André Faria Gomes
 
Java Collections
Java CollectionsJava Collections
Java Collectionsparag
 
Collections framework
Collections frameworkCollections framework
Collections framework
Anand Buddarapu
 
Java Collections
Java  Collections Java  Collections
Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video Tutorial
Marcus Biel
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
Alex Miller
 
Java collections
Java collectionsJava collections
Java collectionsAmar Kutwal
 

What's hot (20)

Java collections notes
Java collections notesJava collections notes
Java collections notes
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Java.util
Java.utilJava.util
Java.util
 
java collections
java collectionsjava collections
java collections
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
20 ch22 collections
20 ch22 collections20 ch22 collections
20 ch22 collections
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google Collections
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Collections framework
Collections frameworkCollections framework
Collections framework
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video Tutorial
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Java collections
Java collectionsJava collections
Java collections
 

Similar to Hash set (java platform se 8 )

Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
charan kumar
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
charan kumar
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
SURBHI SAROHA
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
Zeeshan Khan
 
Array with Iterator. Java styleImplement an array data structure a.pdf
Array with Iterator. Java styleImplement an array data structure a.pdfArray with Iterator. Java styleImplement an array data structure a.pdf
Array with Iterator. Java styleImplement an array data structure a.pdf
fcaindore
 
A04
A04A04
A04
lksoo
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
NJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docx
NJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docxNJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docx
NJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docx
curwenmichaela
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
SURBHI SAROHA
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Sagar Verma
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
IllllBikkySharmaIlll
 
Collection
CollectionCollection
Collection
Guna Sekaran
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate JavaPhilip Johnson
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
SURBHI SAROHA
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
eyemitra1
 
Linked hashmap (java platform se 8 )
Linked hashmap (java platform se 8 )Linked hashmap (java platform se 8 )
Linked hashmap (java platform se 8 )
charan kumar
 
Java collections
Java collectionsJava collections
Java collectionspadmad2291
 
Collections and generic class
Collections and generic classCollections and generic class
Collections and generic class
ifis
 

Similar to Hash set (java platform se 8 ) (20)

Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
Array with Iterator. Java styleImplement an array data structure a.pdf
Array with Iterator. Java styleImplement an array data structure a.pdfArray with Iterator. Java styleImplement an array data structure a.pdf
Array with Iterator. Java styleImplement an array data structure a.pdf
 
A04
A04A04
A04
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
NJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docx
NJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docxNJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docx
NJB_Coll_Lib1javadocallclasses-frame.htmlAll ClassesDynamicArr.docx
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
 
Collection
CollectionCollection
Collection
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate Java
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
 
Linked hashmap (java platform se 8 )
Linked hashmap (java platform se 8 )Linked hashmap (java platform se 8 )
Linked hashmap (java platform se 8 )
 
Java collections
Java collectionsJava collections
Java collections
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Collections
CollectionsCollections
Collections
 
Collections and generic class
Collections and generic classCollections and generic class
Collections and generic class
 

More from charan kumar

Volatile keyword
Volatile keywordVolatile keyword
Volatile keyword
charan kumar
 
Tree map (java platform se 8 )
Tree map (java platform se 8 )Tree map (java platform se 8 )
Tree map (java platform se 8 )
charan kumar
 
The set interface (the java™ tutorials collections interfaces)
The set interface (the java™ tutorials   collections   interfaces)The set interface (the java™ tutorials   collections   interfaces)
The set interface (the java™ tutorials collections interfaces)
charan kumar
 
The map interface (the java™ tutorials collections interfaces)
The map interface (the java™ tutorials   collections   interfaces)The map interface (the java™ tutorials   collections   interfaces)
The map interface (the java™ tutorials collections interfaces)
charan kumar
 
The list interface (the java™ tutorials collections interfaces)
The list interface (the java™ tutorials   collections   interfaces)The list interface (the java™ tutorials   collections   interfaces)
The list interface (the java™ tutorials collections interfaces)
charan kumar
 
Hash map (java platform se 8 )
Hash map (java platform se 8 )Hash map (java platform se 8 )
Hash map (java platform se 8 )
charan kumar
 
Collectn framework
Collectn frameworkCollectn framework
Collectn framework
charan kumar
 
Collectn framework copy
Collectn framework   copyCollectn framework   copy
Collectn framework copy
charan kumar
 

More from charan kumar (8)

Volatile keyword
Volatile keywordVolatile keyword
Volatile keyword
 
Tree map (java platform se 8 )
Tree map (java platform se 8 )Tree map (java platform se 8 )
Tree map (java platform se 8 )
 
The set interface (the java™ tutorials collections interfaces)
The set interface (the java™ tutorials   collections   interfaces)The set interface (the java™ tutorials   collections   interfaces)
The set interface (the java™ tutorials collections interfaces)
 
The map interface (the java™ tutorials collections interfaces)
The map interface (the java™ tutorials   collections   interfaces)The map interface (the java™ tutorials   collections   interfaces)
The map interface (the java™ tutorials collections interfaces)
 
The list interface (the java™ tutorials collections interfaces)
The list interface (the java™ tutorials   collections   interfaces)The list interface (the java™ tutorials   collections   interfaces)
The list interface (the java™ tutorials collections interfaces)
 
Hash map (java platform se 8 )
Hash map (java platform se 8 )Hash map (java platform se 8 )
Hash map (java platform se 8 )
 
Collectn framework
Collectn frameworkCollectn framework
Collectn framework
 
Collectn framework copy
Collectn framework   copyCollectn framework   copy
Collectn framework copy
 

Recently uploaded

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

Hash set (java platform se 8 )

  • 1. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 1/8 OVERVIEW PACKAGE CLASS USE TREE DEPRECATED INDEX HELP Java™ Platform Standard Ed. 8 PREV CLASS NEXT CLASS FRAMES NO FRAMES ALL CLASSES SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD compact1, compact2, compact3 java.util Class HashSet<E> java.lang.Object java.util.AbstractCollection<E> java.util.AbstractSet<E> java.util.HashSet<E> Type Parameters: E - the type of elements maintained by this set All Implemented Interfaces: Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E> Direct Known Subclasses: JobStateReasons, LinkedHashSet public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, Serializable This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element. This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the HashSet instance's size (the number of elements) plus the "capacity" of the backing HashMap instance (the number of buckets). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important. Note that this implementation is not synchronized. If multiple threads access a hash set concurrently, and at least one of the threads modifies the set, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the set. If no such object exists, the set should be "wrapped" using the Collections.synchronizedSet method. This is best done at creation time, to prevent accidental unsynchronized access to the set: Set s = Collections.synchronizedSet(new HashSet(...)); The iterators returned by this class's iterator method are fail-fast: if the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the Iterator throws a ConcurrentModificationException. Thus, in the face of concurrent
  • 2. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 2/8 modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non- deterministic behavior at an undetermined time in the future. Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs. This class is a member of the Java Collections Framework. Since: 1.2 See Also: Collection, Set, TreeSet, HashMap, Serialized Form Constructor Summary Constructor and Description HashSet() Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75). HashSet(Collection<? extends E> c) Constructs a new set containing the elements in the specified collection. HashSet(int initialCapacity) Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75). HashSet(int initialCapacity, float loadFactor) Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and the specified load factor. Method Summary Modifier and Type Method and Description boolean add(E e) Adds the specified element to this set if it is not already present. void clear() Removes all of the elements from this set. Object clone() Constructors All Methods Instance Methods Concrete Methods
  • 3. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 3/8 Returns a shallow copy of this HashSet instance: the elements themselves are not cloned. boolean contains(Object o) Returns true if this set contains the specified element. boolean isEmpty() Returns true if this set contains no elements. Iterator<E> iterator() Returns an iterator over the elements in this set. boolean remove(Object o) Removes the specified element from this set if it is present. int size() Returns the number of elements in this set (its cardinality). Spliterator<E> spliterator() Creates a late-binding and fail-fast Spliterator over the elements in this set. Methods inherited from class java.util.AbstractSet equals, hashCode, removeAll Methods inherited from class java.util.AbstractCollection addAll, containsAll, retainAll, toArray, toArray, toString Methods inherited from class java.lang.Object finalize, getClass, notify, notifyAll, wait, wait, wait Methods inherited from interface java.util.Set addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray Methods inherited from interface java.util.Collection parallelStream, removeIf, stream Methods inherited from interface java.lang.Iterable forEach Constructor Detail
  • 4. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 4/8 HashSet public HashSet() Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75). HashSet public HashSet(Collection<? extends E> c) Constructs a new set containing the elements in the specified collection. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection. Parameters: c - the collection whose elements are to be placed into this set Throws: NullPointerException - if the specified collection is null HashSet public HashSet(int initialCapacity, float loadFactor) Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and the specified load factor. Parameters: initialCapacity - the initial capacity of the hash map loadFactor - the load factor of the hash map Throws: IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive HashSet public HashSet(int initialCapacity) Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75). Parameters: initialCapacity - the initial capacity of the hash table Throws: IllegalArgumentException - if the initial capacity is less than zero
  • 5. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 5/8 Method Detail iterator public Iterator<E> iterator() Returns an iterator over the elements in this set. The elements are returned in no particular order. Specified by: iterator in interface Iterable<E> Specified by: iterator in interface Collection<E> Specified by: iterator in interface Set<E> Specified by: iterator in class AbstractCollection<E> Returns: an Iterator over the elements in this set See Also: ConcurrentModificationException size public int size() Returns the number of elements in this set (its cardinality). Specified by: size in interface Collection<E> Specified by: size in interface Set<E> Specified by: size in class AbstractCollection<E> Returns: the number of elements in this set (its cardinality) isEmpty public boolean isEmpty()
  • 6. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 6/8 Returns true if this set contains no elements. Specified by: isEmpty in interface Collection<E> Specified by: isEmpty in interface Set<E> Overrides: isEmpty in class AbstractCollection<E> Returns: true if this set contains no elements contains public boolean contains(Object o) Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)). Specified by: contains in interface Collection<E> Specified by: contains in interface Set<E> Overrides: contains in class AbstractCollection<E> Parameters: o - element whose presence in this set is to be tested Returns: true if this set contains the specified element add public boolean add(E e) Adds the specified element to this set if it is not already present. More formally, adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false. Specified by: add in interface Collection<E> Specified by: add in interface Set<E> Overrides: add in class AbstractCollection<E>
  • 7. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 7/8 Parameters: e - element to be added to this set Returns: true if this set did not already contain the specified element remove public boolean remove(Object o) Removes the specified element from this set if it is present. More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.) Specified by: remove in interface Collection<E> Specified by: remove in interface Set<E> Overrides: remove in class AbstractCollection<E> Parameters: o - object to be removed from this set, if present Returns: true if the set contained the specified element clear public void clear() Removes all of the elements from this set. The set will be empty after this call returns. Specified by: clear in interface Collection<E> Specified by: clear in interface Set<E> Overrides: clear in class AbstractCollection<E> clone public Object clone() Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.
  • 8. 8/30/2016 HashSet (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html 8/8 OVERVIEW PACKAGE CLASS USE TREE DEPRECATED INDEX HELP Java™ Platform Standard Ed. 8 PREV CLASS NEXT CLASS FRAMES NO FRAMES ALL CLASSES SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy. Overrides: clone in class Object Returns: a shallow copy of this set See Also: Cloneable spliterator public Spliterator<E> spliterator() Creates a late-binding and fail-fast Spliterator over the elements in this set. The Spliterator reports Spliterator.SIZED and Spliterator.DISTINCT. Overriding implementations should document the reporting of additional characteristic values. Specified by: spliterator in interface Iterable<E> Specified by: spliterator in interface Collection<E> Specified by: spliterator in interface Set<E> Returns: a Spliterator over the elements in this set Since: 1.8