< prev index next >

src/java.base/share/classes/java/lang/Boolean.java

Print this page




  66     public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");
  67 
  68     /**
  69      * The value of the Boolean.
  70      *
  71      * @serial
  72      */
  73     private final boolean value;
  74 
  75     /** use serialVersionUID from JDK 1.0.2 for interoperability */
  76     private static final long serialVersionUID = -3665804199014368530L;
  77 
  78     /**
  79      * Allocates a {@code Boolean} object representing the
  80      * {@code value} argument.
  81      *
  82      * <p><b>Note: It is rarely appropriate to use this constructor.
  83      * Unless a <i>new</i> instance is required, the static factory
  84      * {@link #valueOf(boolean)} is generally a better choice. It is
  85      * likely to yield significantly better space and time performance.</b>

  86      *
  87      * @param   value   the value of the {@code Boolean}.
  88      */

  89     public Boolean(boolean value) {
  90         this.value = value;
  91     }
  92 
  93     /**
  94      * Allocates a {@code Boolean} object representing the value
  95      * {@code true} if the string argument is not {@code null}
  96      * and is equal, ignoring case, to the string {@code "true"}.
  97      * Otherwise, allocate a {@code Boolean} object representing the
  98      * value {@code false}. Examples:<p>
  99      * {@code new Boolean("True")} produces a {@code Boolean} object
 100      * that represents {@code true}.<br>
 101      * {@code new Boolean("yes")} produces a {@code Boolean} object
 102      * that represents {@code false}.

 103      *
 104      * @param   s   the string to be converted to a {@code Boolean}.
 105      */

 106     public Boolean(String s) {
 107         this(parseBoolean(s));
 108     }
 109 
 110     /**
 111      * Parses the string argument as a boolean.  The {@code boolean}
 112      * returned represents the value {@code true} if the string argument
 113      * is not {@code null} and is equal, ignoring case, to the string
 114      * {@code "true"}. <p>
 115      * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
 116      * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
 117      *
 118      * @param      s   the {@code String} containing the boolean
 119      *                 representation to be parsed
 120      * @return     the boolean represented by the string argument
 121      * @since 1.5
 122      */
 123     public static boolean parseBoolean(String s) {
 124         return ((s != null) && s.equalsIgnoreCase("true"));
 125     }




  66     public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");
  67 
  68     /**
  69      * The value of the Boolean.
  70      *
  71      * @serial
  72      */
  73     private final boolean value;
  74 
  75     /** use serialVersionUID from JDK 1.0.2 for interoperability */
  76     private static final long serialVersionUID = -3665804199014368530L;
  77 
  78     /**
  79      * Allocates a {@code Boolean} object representing the
  80      * {@code value} argument.
  81      *
  82      * <p><b>Note: It is rarely appropriate to use this constructor.
  83      * Unless a <i>new</i> instance is required, the static factory
  84      * {@link #valueOf(boolean)} is generally a better choice. It is
  85      * likely to yield significantly better space and time performance.</b>
  86      * @deprecated use {@link #valueOf(boolean)} instead. 
  87      *
  88      * @param   value   the value of the {@code Boolean}.
  89      */
  90     @Deprecated
  91     public Boolean(boolean value) {
  92         this.value = value;
  93     }
  94 
  95     /**
  96      * Allocates a {@code Boolean} object representing the value
  97      * {@code true} if the string argument is not {@code null}
  98      * and is equal, ignoring case, to the string {@code "true"}.
  99      * Otherwise, allocate a {@code Boolean} object representing the
 100      * value {@code false}. Examples:<p>
 101      * {@code new Boolean("True")} produces a {@code Boolean} object
 102      * that represents {@code true}.<br>
 103      * {@code new Boolean("yes")} produces a {@code Boolean} object
 104      * that represents {@code false}.
 105      * @deprecated use {@link #valueOf(String)} instead. 
 106      *
 107      * @param   s   the string to be converted to a {@code Boolean}.
 108      */
 109     @Deprecated
 110     public Boolean(String s) {
 111         this(parseBoolean(s));
 112     }
 113 
 114     /**
 115      * Parses the string argument as a boolean.  The {@code boolean}
 116      * returned represents the value {@code true} if the string argument
 117      * is not {@code null} and is equal, ignoring case, to the string
 118      * {@code "true"}. <p>
 119      * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
 120      * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
 121      *
 122      * @param      s   the {@code String} containing the boolean
 123      *                 representation to be parsed
 124      * @return     the boolean represented by the string argument
 125      * @since 1.5
 126      */
 127     public static boolean parseBoolean(String s) {
 128         return ((s != null) && s.equalsIgnoreCase("true"));
 129     }


< prev index next >