src/share/classes/java/lang/Byte.java

Print this page




 184      * int)} method. The result is a {@code Byte} object that
 185      * represents the {@code byte} value specified by the string.
 186      *
 187      * <p> In other words, this method returns a {@code Byte} object
 188      * equal to the value of:
 189      *
 190      * <blockquote>
 191      * {@code new Byte(Byte.parseByte(s, radix))}
 192      * </blockquote>
 193      *
 194      * @param s         the string to be parsed
 195      * @param radix     the radix to be used in interpreting {@code s}
 196      * @return          a {@code Byte} object holding the value
 197      *                  represented by the string argument in the
 198      *                  specified radix.
 199      * @throws          NumberFormatException If the {@code String} does
 200      *                  not contain a parsable {@code byte}.
 201      */
 202     public static Byte valueOf(String s, int radix)
 203         throws NumberFormatException {
 204         return new Byte(parseByte(s, radix));
 205     }
 206 
 207     /**
 208      * Returns a {@code Byte} object holding the value
 209      * given by the specified {@code String}. The argument is
 210      * interpreted as representing a signed decimal {@code byte},
 211      * exactly as if the argument were given to the {@link
 212      * #parseByte(java.lang.String)} method. The result is a
 213      * {@code Byte} object that represents the {@code byte}
 214      * value specified by the string.
 215      *
 216      * <p> In other words, this method returns a {@code Byte} object
 217      * equal to the value of:
 218      *
 219      * <blockquote>
 220      * {@code new Byte(Byte.parseByte(s))}
 221      * </blockquote>
 222      *
 223      * @param s         the string to be parsed
 224      * @return          a {@code Byte} object holding the value


 260      * "{@code #}", or leading zero) is parsed as by the {@code
 261      * Byte.parseByte} method with the indicated radix (10, 16, or 8).
 262      * This sequence of characters must represent a positive value or
 263      * a {@link NumberFormatException} will be thrown.  The result is
 264      * negated if first character of the specified {@code String} is
 265      * the minus sign.  No whitespace characters are permitted in the
 266      * {@code String}.
 267      *
 268      * @param     nm the {@code String} to decode.
 269      * @return   a {@code Byte} object holding the {@code byte}
 270      *          value represented by {@code nm}
 271      * @throws  NumberFormatException  if the {@code String} does not
 272      *            contain a parsable {@code byte}.
 273      * @see java.lang.Byte#parseByte(java.lang.String, int)
 274      */
 275     public static Byte decode(String nm) throws NumberFormatException {
 276         int i = Integer.decode(nm);
 277         if (i < MIN_VALUE || i > MAX_VALUE)
 278             throw new NumberFormatException(
 279                     "Value " + i + " out of range from input " + nm);
 280         return (byte)i;
 281     }
 282 
 283     /**
 284      * The value of the {@code Byte}.
 285      *
 286      * @serial
 287      */
 288     private final byte value;
 289 
 290     /**
 291      * Constructs a newly allocated {@code Byte} object that
 292      * represents the specified {@code byte} value.
 293      *
 294      * @param value     the value to be represented by the
 295      *                  {@code Byte}.
 296      */
 297     public Byte(byte value) {
 298         this.value = value;
 299     }
 300 


 357 
 358     /**
 359      * Returns the value of this {@code Byte} as a
 360      * {@code double}.
 361      */
 362     public double doubleValue() {
 363         return (double)value;
 364     }
 365 
 366     /**
 367      * Returns a {@code String} object representing this
 368      * {@code Byte}'s value.  The value is converted to signed
 369      * decimal representation and returned as a string, exactly as if
 370      * the {@code byte} value were given as an argument to the
 371      * {@link java.lang.Byte#toString(byte)} method.
 372      *
 373      * @return  a string representation of the value of this object in
 374      *          base&nbsp;10.
 375      */
 376     public String toString() {
 377         return String.valueOf((int)value);
 378     }
 379 
 380     /**
 381      * Returns a hash code for this {@code Byte}; equal to the result
 382      * of invoking {@code intValue()}.
 383      *
 384      * @return a hash code value for this {@code Byte}
 385      */
 386     public int hashCode() {
 387         return (int)value;
 388     }
 389 
 390     /**
 391      * Compares this object to the specified object.  The result is
 392      * {@code true} if and only if the argument is not
 393      * {@code null} and is a {@code Byte} object that
 394      * contains the same {@code byte} value as this object.
 395      *
 396      * @param obj       the object to compare with
 397      * @return          {@code true} if the objects are the same;




 184      * int)} method. The result is a {@code Byte} object that
 185      * represents the {@code byte} value specified by the string.
 186      *
 187      * <p> In other words, this method returns a {@code Byte} object
 188      * equal to the value of:
 189      *
 190      * <blockquote>
 191      * {@code new Byte(Byte.parseByte(s, radix))}
 192      * </blockquote>
 193      *
 194      * @param s         the string to be parsed
 195      * @param radix     the radix to be used in interpreting {@code s}
 196      * @return          a {@code Byte} object holding the value
 197      *                  represented by the string argument in the
 198      *                  specified radix.
 199      * @throws          NumberFormatException If the {@code String} does
 200      *                  not contain a parsable {@code byte}.
 201      */
 202     public static Byte valueOf(String s, int radix)
 203         throws NumberFormatException {
 204         return valueOf(parseByte(s, radix));
 205     }
 206 
 207     /**
 208      * Returns a {@code Byte} object holding the value
 209      * given by the specified {@code String}. The argument is
 210      * interpreted as representing a signed decimal {@code byte},
 211      * exactly as if the argument were given to the {@link
 212      * #parseByte(java.lang.String)} method. The result is a
 213      * {@code Byte} object that represents the {@code byte}
 214      * value specified by the string.
 215      *
 216      * <p> In other words, this method returns a {@code Byte} object
 217      * equal to the value of:
 218      *
 219      * <blockquote>
 220      * {@code new Byte(Byte.parseByte(s))}
 221      * </blockquote>
 222      *
 223      * @param s         the string to be parsed
 224      * @return          a {@code Byte} object holding the value


 260      * "{@code #}", or leading zero) is parsed as by the {@code
 261      * Byte.parseByte} method with the indicated radix (10, 16, or 8).
 262      * This sequence of characters must represent a positive value or
 263      * a {@link NumberFormatException} will be thrown.  The result is
 264      * negated if first character of the specified {@code String} is
 265      * the minus sign.  No whitespace characters are permitted in the
 266      * {@code String}.
 267      *
 268      * @param     nm the {@code String} to decode.
 269      * @return   a {@code Byte} object holding the {@code byte}
 270      *          value represented by {@code nm}
 271      * @throws  NumberFormatException  if the {@code String} does not
 272      *            contain a parsable {@code byte}.
 273      * @see java.lang.Byte#parseByte(java.lang.String, int)
 274      */
 275     public static Byte decode(String nm) throws NumberFormatException {
 276         int i = Integer.decode(nm);
 277         if (i < MIN_VALUE || i > MAX_VALUE)
 278             throw new NumberFormatException(
 279                     "Value " + i + " out of range from input " + nm);
 280         return valueOf((byte)i);
 281     }
 282 
 283     /**
 284      * The value of the {@code Byte}.
 285      *
 286      * @serial
 287      */
 288     private final byte value;
 289 
 290     /**
 291      * Constructs a newly allocated {@code Byte} object that
 292      * represents the specified {@code byte} value.
 293      *
 294      * @param value     the value to be represented by the
 295      *                  {@code Byte}.
 296      */
 297     public Byte(byte value) {
 298         this.value = value;
 299     }
 300 


 357 
 358     /**
 359      * Returns the value of this {@code Byte} as a
 360      * {@code double}.
 361      */
 362     public double doubleValue() {
 363         return (double)value;
 364     }
 365 
 366     /**
 367      * Returns a {@code String} object representing this
 368      * {@code Byte}'s value.  The value is converted to signed
 369      * decimal representation and returned as a string, exactly as if
 370      * the {@code byte} value were given as an argument to the
 371      * {@link java.lang.Byte#toString(byte)} method.
 372      *
 373      * @return  a string representation of the value of this object in
 374      *          base&nbsp;10.
 375      */
 376     public String toString() {
 377         return Integer.toString((int)value);
 378     }
 379 
 380     /**
 381      * Returns a hash code for this {@code Byte}; equal to the result
 382      * of invoking {@code intValue()}.
 383      *
 384      * @return a hash code value for this {@code Byte}
 385      */
 386     public int hashCode() {
 387         return (int)value;
 388     }
 389 
 390     /**
 391      * Compares this object to the specified object.  The result is
 392      * {@code true} if and only if the argument is not
 393      * {@code null} and is a {@code Byte} object that
 394      * contains the same {@code byte} value as this object.
 395      *
 396      * @param obj       the object to compare with
 397      * @return          {@code true} if the objects are the same;