100 * Otherwise, allocates a {@code Boolean} object representing the
101 * value {@code false}.
102 *
103 * @param s the string to be converted to a {@code Boolean}.
104 *
105 * @deprecated
106 * It is rarely appropriate to use this constructor.
107 * Use {@link #parseBoolean(String)} to convert a string to a
108 * {@code boolean} primitive, or use {@link #valueOf(String)}
109 * to convert a string to a {@code Boolean} object.
110 */
111 @Deprecated(since="9")
112 public Boolean(String s) {
113 this(parseBoolean(s));
114 }
115
116 /**
117 * Parses the string argument as a boolean. The {@code boolean}
118 * returned represents the value {@code true} if the string argument
119 * is not {@code null} and is equal, ignoring case, to the string
120 * {@code "true"}. <p>
121 * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
122 * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
123 *
124 * @param s the {@code String} containing the boolean
125 * representation to be parsed
126 * @return the boolean represented by the string argument
127 * @since 1.5
128 */
129 public static boolean parseBoolean(String s) {
130 return ((s != null) && s.equalsIgnoreCase("true"));
131 }
132
133 /**
134 * Returns the value of this {@code Boolean} object as a boolean
135 * primitive.
136 *
137 * @return the primitive {@code boolean} value of this object.
138 */
139 @HotSpotIntrinsicCandidate
140 public boolean booleanValue() {
148 * if it is {@code false}, this method returns {@code Boolean.FALSE}.
149 * If a new {@code Boolean} instance is not required, this method
150 * should generally be used in preference to the constructor
151 * {@link #Boolean(boolean)}, as this method is likely to yield
152 * significantly better space and time performance.
153 *
154 * @param b a boolean value.
155 * @return a {@code Boolean} instance representing {@code b}.
156 * @since 1.4
157 */
158 @HotSpotIntrinsicCandidate
159 public static Boolean valueOf(boolean b) {
160 return (b ? TRUE : FALSE);
161 }
162
163 /**
164 * Returns a {@code Boolean} with a value represented by the
165 * specified string. The {@code Boolean} returned represents a
166 * true value if the string argument is not {@code null}
167 * and is equal, ignoring case, to the string {@code "true"}.
168 *
169 * @param s a string.
170 * @return the {@code Boolean} value represented by the string.
171 */
172 public static Boolean valueOf(String s) {
173 return parseBoolean(s) ? TRUE : FALSE;
174 }
175
176 /**
177 * Returns a {@code String} object representing the specified
178 * boolean. If the specified boolean is {@code true}, then
179 * the string {@code "true"} will be returned, otherwise the
180 * string {@code "false"} will be returned.
181 *
182 * @param b the boolean to be converted
183 * @return the string representation of the specified {@code boolean}
184 * @since 1.4
185 */
186 public static String toString(boolean b) {
187 return b ? "true" : "false";
224 }
225
226 /**
227 * Returns {@code true} if and only if the argument is not
228 * {@code null} and is a {@code Boolean} object that
229 * represents the same {@code boolean} value as this object.
230 *
231 * @param obj the object to compare with.
232 * @return {@code true} if the Boolean objects represent the
233 * same value; {@code false} otherwise.
234 */
235 public boolean equals(Object obj) {
236 if (obj instanceof Boolean) {
237 return value == ((Boolean)obj).booleanValue();
238 }
239 return false;
240 }
241
242 /**
243 * Returns {@code true} if and only if the system property named
244 * by the argument exists and is equal to the string {@code
245 * "true"}. (Beginning with version 1.0.2 of the Java™
246 * platform, the test of this string is case insensitive.) A
247 * system property is accessible through {@code getProperty}, a
248 * method defined by the {@code System} class.
249 * <p>
250 * If there is no property with the specified name, or if the specified
251 * name is empty or null, then {@code false} is returned.
252 *
253 * @param name the system property name.
254 * @return the {@code boolean} value of the system property.
255 * @throws SecurityException for the same reasons as
256 * {@link System#getProperty(String) System.getProperty}
257 * @see java.lang.System#getProperty(java.lang.String)
258 * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
259 */
260 public static boolean getBoolean(String name) {
261 boolean result = false;
262 try {
263 result = parseBoolean(System.getProperty(name));
264 } catch (IllegalArgumentException | NullPointerException e) {
265 }
266 return result;
267 }
268
269 /**
270 * Compares this {@code Boolean} instance with another.
271 *
|
100 * Otherwise, allocates a {@code Boolean} object representing the
101 * value {@code false}.
102 *
103 * @param s the string to be converted to a {@code Boolean}.
104 *
105 * @deprecated
106 * It is rarely appropriate to use this constructor.
107 * Use {@link #parseBoolean(String)} to convert a string to a
108 * {@code boolean} primitive, or use {@link #valueOf(String)}
109 * to convert a string to a {@code Boolean} object.
110 */
111 @Deprecated(since="9")
112 public Boolean(String s) {
113 this(parseBoolean(s));
114 }
115
116 /**
117 * Parses the string argument as a boolean. The {@code boolean}
118 * returned represents the value {@code true} if the string argument
119 * is not {@code null} and is equal, ignoring case, to the string
120 * {@code "true"}.
121 * Otherwise, a false value is returned, including for a null
122 * argument.<p>
123 * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
124 * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
125 *
126 * @param s the {@code String} containing the boolean
127 * representation to be parsed
128 * @return the boolean represented by the string argument
129 * @since 1.5
130 */
131 public static boolean parseBoolean(String s) {
132 return ((s != null) && s.equalsIgnoreCase("true"));
133 }
134
135 /**
136 * Returns the value of this {@code Boolean} object as a boolean
137 * primitive.
138 *
139 * @return the primitive {@code boolean} value of this object.
140 */
141 @HotSpotIntrinsicCandidate
142 public boolean booleanValue() {
150 * if it is {@code false}, this method returns {@code Boolean.FALSE}.
151 * If a new {@code Boolean} instance is not required, this method
152 * should generally be used in preference to the constructor
153 * {@link #Boolean(boolean)}, as this method is likely to yield
154 * significantly better space and time performance.
155 *
156 * @param b a boolean value.
157 * @return a {@code Boolean} instance representing {@code b}.
158 * @since 1.4
159 */
160 @HotSpotIntrinsicCandidate
161 public static Boolean valueOf(boolean b) {
162 return (b ? TRUE : FALSE);
163 }
164
165 /**
166 * Returns a {@code Boolean} with a value represented by the
167 * specified string. The {@code Boolean} returned represents a
168 * true value if the string argument is not {@code null}
169 * and is equal, ignoring case, to the string {@code "true"}.
170 * Otherwise, a false value is returned, including for a null
171 * argument.
172 *
173 * @param s a string.
174 * @return the {@code Boolean} value represented by the string.
175 */
176 public static Boolean valueOf(String s) {
177 return parseBoolean(s) ? TRUE : FALSE;
178 }
179
180 /**
181 * Returns a {@code String} object representing the specified
182 * boolean. If the specified boolean is {@code true}, then
183 * the string {@code "true"} will be returned, otherwise the
184 * string {@code "false"} will be returned.
185 *
186 * @param b the boolean to be converted
187 * @return the string representation of the specified {@code boolean}
188 * @since 1.4
189 */
190 public static String toString(boolean b) {
191 return b ? "true" : "false";
228 }
229
230 /**
231 * Returns {@code true} if and only if the argument is not
232 * {@code null} and is a {@code Boolean} object that
233 * represents the same {@code boolean} value as this object.
234 *
235 * @param obj the object to compare with.
236 * @return {@code true} if the Boolean objects represent the
237 * same value; {@code false} otherwise.
238 */
239 public boolean equals(Object obj) {
240 if (obj instanceof Boolean) {
241 return value == ((Boolean)obj).booleanValue();
242 }
243 return false;
244 }
245
246 /**
247 * Returns {@code true} if and only if the system property named
248 * by the argument exists and is equal to, ignoring case, the
249 * string {@code "true"}.
250 * A system property is accessible through {@code getProperty}, a
251 * method defined by the {@code System} class. <p> If there is no
252 * property with the specified name, or if the specified name is
253 * empty or null, then {@code false} is returned.
254 *
255 * @param name the system property name.
256 * @return the {@code boolean} value of the system property.
257 * @throws SecurityException for the same reasons as
258 * {@link System#getProperty(String) System.getProperty}
259 * @see java.lang.System#getProperty(java.lang.String)
260 * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
261 */
262 public static boolean getBoolean(String name) {
263 boolean result = false;
264 try {
265 result = parseBoolean(System.getProperty(name));
266 } catch (IllegalArgumentException | NullPointerException e) {
267 }
268 return result;
269 }
270
271 /**
272 * Compares this {@code Boolean} instance with another.
273 *
|