Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4492232

HashSet.remove() doesn`t work with null elements

XMLWordPrintable

    • beta2
    • sparc
    • solaris_2.6
    • Verified



      Name: auR10023 Date: 08/15/2001



      java.util.HashSet.remove(Object ) doesn`t work with null elements.
      This method returns false for null element.

      Here is the example:

      ---------------t.java---------------
      import java.util.*;

      class t {
          public static void main(String [] args) {
              HashSet hs = new HashSet();
              hs.add(null);
              System.out.println(hs.remove(null));
          }
      }
       


      #java -version
      java -version
      java version "1.4.0-beta_refresh"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b75)
      Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b75, mixed mode)

      #java -cp . t
      false

      #java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

      #java -cp .t
      true

      ======================================================================

            jjb Josh Bloch
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: