< prev index next >

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

Print this page




 188      * <p>In other words, this method returns a {@code Short} object
 189      * equal to the value of:
 190      *
 191      * <blockquote>
 192      *  {@code new Short(Short.parseShort(s))}
 193      * </blockquote>
 194      *
 195      * @param s the string to be parsed
 196      * @return  a {@code Short} object holding the value
 197      *          represented by the string argument
 198      * @throws  NumberFormatException If the {@code String} does
 199      *          not contain a parsable {@code short}.
 200      */
 201     public static Short valueOf(String s) throws NumberFormatException {
 202         return valueOf(s, 10);
 203     }
 204 
 205     private static class ShortCache {
 206         private ShortCache(){}
 207 
 208         static final Short cache[] = new Short[-(-128) + 127 + 1];
 209 
 210         static {
 211             for(int i = 0; i < cache.length; i++)
 212                 cache[i] = new Short((short)(i - 128));
 213         }
 214     }
 215 
 216     /**
 217      * Returns a {@code Short} instance representing the specified
 218      * {@code short} value.
 219      * If a new {@code Short} instance is not required, this method
 220      * should generally be used in preference to the constructor
 221      * {@link #Short(short)}, as this method is likely to yield
 222      * significantly better space and time performance by caching
 223      * frequently requested values.
 224      *
 225      * This method will always cache values in the range -128 to 127,
 226      * inclusive, and may cache other values outside of this range.
 227      *
 228      * @param  s a short value.




 188      * <p>In other words, this method returns a {@code Short} object
 189      * equal to the value of:
 190      *
 191      * <blockquote>
 192      *  {@code new Short(Short.parseShort(s))}
 193      * </blockquote>
 194      *
 195      * @param s the string to be parsed
 196      * @return  a {@code Short} object holding the value
 197      *          represented by the string argument
 198      * @throws  NumberFormatException If the {@code String} does
 199      *          not contain a parsable {@code short}.
 200      */
 201     public static Short valueOf(String s) throws NumberFormatException {
 202         return valueOf(s, 10);
 203     }
 204 
 205     private static class ShortCache {
 206         private ShortCache(){}
 207 
 208         static final Short[] cache = new Short[-(-128) + 127 + 1];
 209 
 210         static {
 211             for(int i = 0; i < cache.length; i++)
 212                 cache[i] = new Short((short)(i - 128));
 213         }
 214     }
 215 
 216     /**
 217      * Returns a {@code Short} instance representing the specified
 218      * {@code short} value.
 219      * If a new {@code Short} instance is not required, this method
 220      * should generally be used in preference to the constructor
 221      * {@link #Short(short)}, as this method is likely to yield
 222      * significantly better space and time performance by caching
 223      * frequently requested values.
 224      *
 225      * This method will always cache values in the range -128 to 127,
 226      * inclusive, and may cache other values outside of this range.
 227      *
 228      * @param  s a short value.


< prev index next >