93 * {@link #Byte(byte)}, as this method is likely to yield 94 * significantly better space and time performance since 95 * all byte values are cached. 96 * 97 * @param b a byte value. 98 * @return a {@code Byte} instance representing {@code b}. 99 * @since 1.5 100 */ 101 public static Byte valueOf(byte b) { 102 final int offset = 128; 103 return ByteCache.cache[(int)b + offset]; 104 } 105 106 /** 107 * Parses the string argument as a signed {@code byte} in the 108 * radix specified by the second argument. The characters in the 109 * string must all be digits, of the specified radix (as 110 * determined by whether {@link java.lang.Character#digit(char, 111 * int)} returns a nonnegative value) except that the first 112 * character may be an ASCII minus sign {@code '-'} 113 * (<code>'\u002D'</code>) to indicate a negative value or an 114 * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to 115 * indicate a positive value. The resulting {@code byte} value is 116 * returned. 117 * 118 * <p>An exception of type {@code NumberFormatException} is 119 * thrown if any of the following situations occurs: 120 * <ul> 121 * <li> The first argument is {@code null} or is a string of 122 * length zero. 123 * 124 * <li> The radix is either smaller than {@link 125 * java.lang.Character#MIN_RADIX} or larger than {@link 126 * java.lang.Character#MAX_RADIX}. 127 * 128 * <li> Any character of the string is not a digit of the 129 * specified radix, except that the first character may be a minus 130 * sign {@code '-'} (<code>'\u002D'</code>) or plus sign 131 * {@code '+'} (<code>'\u002B'</code>) provided that the 132 * string is longer than length 1. 133 * 134 * <li> The value represented by the string is not a value of type 135 * {@code byte}. 136 * </ul> 137 * 138 * @param s the {@code String} containing the 139 * {@code byte} 140 * representation to be parsed 141 * @param radix the radix to be used while parsing {@code s} 142 * @return the {@code byte} value represented by the string 143 * argument in the specified radix 144 * @throws NumberFormatException If the string does 145 * not contain a parsable {@code byte}. 146 */ 147 public static byte parseByte(String s, int radix) 148 throws NumberFormatException { 149 int i = Integer.parseInt(s, radix); 150 if (i < MIN_VALUE || i > MAX_VALUE) 151 throw new NumberFormatException( 152 "Value out of range. Value:\"" + s + "\" Radix:" + radix); 153 return (byte)i; 154 } 155 156 /** 157 * Parses the string argument as a signed decimal {@code 158 * byte}. The characters in the string must all be decimal digits, 159 * except that the first character may be an ASCII minus sign 160 * {@code '-'} (<code>'\u002D'</code>) to indicate a negative 161 * value or an ASCII plus sign {@code '+'} 162 * (<code>'\u002B'</code>) to indicate a positive value. The 163 * resulting {@code byte} value is returned, exactly as if the 164 * argument and the radix 10 were given as arguments to the {@link 165 * #parseByte(java.lang.String, int)} method. 166 * 167 * @param s a {@code String} containing the 168 * {@code byte} representation to be parsed 169 * @return the {@code byte} value represented by the 170 * argument in decimal 171 * @throws NumberFormatException if the string does not 172 * contain a parsable {@code byte}. 173 */ 174 public static byte parseByte(String s) throws NumberFormatException { 175 return parseByte(s, 10); 176 } 177 178 /** 179 * Returns a {@code Byte} object holding the value 180 * extracted from the specified {@code String} when parsed 181 * with the radix given by the second argument. The first argument 182 * is interpreted as representing a signed {@code byte} in | 93 * {@link #Byte(byte)}, as this method is likely to yield 94 * significantly better space and time performance since 95 * all byte values are cached. 96 * 97 * @param b a byte value. 98 * @return a {@code Byte} instance representing {@code b}. 99 * @since 1.5 100 */ 101 public static Byte valueOf(byte b) { 102 final int offset = 128; 103 return ByteCache.cache[(int)b + offset]; 104 } 105 106 /** 107 * Parses the string argument as a signed {@code byte} in the 108 * radix specified by the second argument. The characters in the 109 * string must all be digits, of the specified radix (as 110 * determined by whether {@link java.lang.Character#digit(char, 111 * int)} returns a nonnegative value) except that the first 112 * character may be an ASCII minus sign {@code '-'} 113 * ({@code '\u005Cu002D'}) to indicate a negative value or an 114 * ASCII plus sign {@code '+'} ({@code '\u005Cu002B'}) to 115 * indicate a positive value. The resulting {@code byte} value is 116 * returned. 117 * 118 * <p>An exception of type {@code NumberFormatException} is 119 * thrown if any of the following situations occurs: 120 * <ul> 121 * <li> The first argument is {@code null} or is a string of 122 * length zero. 123 * 124 * <li> The radix is either smaller than {@link 125 * java.lang.Character#MIN_RADIX} or larger than {@link 126 * java.lang.Character#MAX_RADIX}. 127 * 128 * <li> Any character of the string is not a digit of the 129 * specified radix, except that the first character may be a minus 130 * sign {@code '-'} ({@code '\u005Cu002D'}) or plus sign 131 * {@code '+'} ({@code '\u005Cu002B'}) provided that the 132 * string is longer than length 1. 133 * 134 * <li> The value represented by the string is not a value of type 135 * {@code byte}. 136 * </ul> 137 * 138 * @param s the {@code String} containing the 139 * {@code byte} 140 * representation to be parsed 141 * @param radix the radix to be used while parsing {@code s} 142 * @return the {@code byte} value represented by the string 143 * argument in the specified radix 144 * @throws NumberFormatException If the string does 145 * not contain a parsable {@code byte}. 146 */ 147 public static byte parseByte(String s, int radix) 148 throws NumberFormatException { 149 int i = Integer.parseInt(s, radix); 150 if (i < MIN_VALUE || i > MAX_VALUE) 151 throw new NumberFormatException( 152 "Value out of range. Value:\"" + s + "\" Radix:" + radix); 153 return (byte)i; 154 } 155 156 /** 157 * Parses the string argument as a signed decimal {@code 158 * byte}. The characters in the string must all be decimal digits, 159 * except that the first character may be an ASCII minus sign 160 * {@code '-'} ({@code '\u005Cu002D'}) to indicate a negative 161 * value or an ASCII plus sign {@code '+'} 162 * ({@code '\u005Cu002B'}) to indicate a positive value. The 163 * resulting {@code byte} value is returned, exactly as if the 164 * argument and the radix 10 were given as arguments to the {@link 165 * #parseByte(java.lang.String, int)} method. 166 * 167 * @param s a {@code String} containing the 168 * {@code byte} representation to be parsed 169 * @return the {@code byte} value represented by the 170 * argument in decimal 171 * @throws NumberFormatException if the string does not 172 * contain a parsable {@code byte}. 173 */ 174 public static byte parseByte(String s) throws NumberFormatException { 175 return parseByte(s, 10); 176 } 177 178 /** 179 * Returns a {@code Byte} object holding the value 180 * extracted from the specified {@code String} when parsed 181 * with the radix given by the second argument. The first argument 182 * is interpreted as representing a signed {@code byte} in |