< prev index next >

src/java.base/share/classes/java/util/HashSet.java

Print this page
rev 51958 : 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
Reviewed-by: alanb, dfuchs, kvn


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util;
  27 
  28 import java.io.InvalidObjectException;
  29 import jdk.internal.misc.SharedSecrets;
  30 
  31 /**
  32  * This class implements the {@code Set} interface, backed by a hash table
  33  * (actually a {@code HashMap} instance).  It makes no guarantees as to the
  34  * iteration order of the set; in particular, it does not guarantee that the
  35  * order will remain constant over time.  This class permits the {@code null}
  36  * element.
  37  *
  38  * <p>This class offers constant time performance for the basic operations
  39  * ({@code add}, {@code remove}, {@code contains} and {@code size}),
  40  * assuming the hash function disperses the elements properly among the
  41  * buckets.  Iterating over this set requires time proportional to the sum of
  42  * the {@code HashSet} instance's size (the number of elements) plus the
  43  * "capacity" of the backing {@code HashMap} instance (the number of
  44  * buckets).  Thus, it's very important not to set the initial capacity too
  45  * high (or the load factor too low) if iteration performance is important.
  46  *
  47  * <p><strong>Note that this implementation is not synchronized.</strong>
  48  * If multiple threads access a hash set concurrently, and at least one of
  49  * the threads modifies the set, it <i>must</i> be synchronized externally.




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util;
  27 
  28 import java.io.InvalidObjectException;
  29 import jdk.internal.access.SharedSecrets;
  30 
  31 /**
  32  * This class implements the {@code Set} interface, backed by a hash table
  33  * (actually a {@code HashMap} instance).  It makes no guarantees as to the
  34  * iteration order of the set; in particular, it does not guarantee that the
  35  * order will remain constant over time.  This class permits the {@code null}
  36  * element.
  37  *
  38  * <p>This class offers constant time performance for the basic operations
  39  * ({@code add}, {@code remove}, {@code contains} and {@code size}),
  40  * assuming the hash function disperses the elements properly among the
  41  * buckets.  Iterating over this set requires time proportional to the sum of
  42  * the {@code HashSet} instance's size (the number of elements) plus the
  43  * "capacity" of the backing {@code HashMap} instance (the number of
  44  * buckets).  Thus, it's very important not to set the initial capacity too
  45  * high (or the load factor too low) if iteration performance is important.
  46  *
  47  * <p><strong>Note that this implementation is not synchronized.</strong>
  48  * If multiple threads access a hash set concurrently, and at least one of
  49  * the threads modifies the set, it <i>must</i> be synchronized externally.


< prev index next >