src/share/classes/java/lang/Integer.java

Print this page


   1 /*
   2  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 661     }
 662 
 663     /**
 664      * Constructs a newly allocated {@code Integer} object that
 665      * represents the {@code int} value indicated by the
 666      * {@code String} parameter. The string is converted to an
 667      * {@code int} value in exactly the manner used by the
 668      * {@code parseInt} method for radix 10.
 669      *
 670      * @param      s   the {@code String} to be converted to an
 671      *                 {@code Integer}.
 672      * @exception  NumberFormatException  if the {@code String} does not
 673      *               contain a parsable integer.
 674      * @see        java.lang.Integer#parseInt(java.lang.String, int)
 675      */
 676     public Integer(String s) throws NumberFormatException {
 677         this.value = parseInt(s, 10);
 678     }
 679 
 680     /**
 681      * Returns the value of this {@code Integer} as a
 682      * {@code byte}.

 683      */
 684     public byte byteValue() {
 685         return (byte)value;
 686     }
 687 
 688     /**
 689      * Returns the value of this {@code Integer} as a
 690      * {@code short}.

 691      */
 692     public short shortValue() {
 693         return (short)value;
 694     }
 695 
 696     /**
 697      * Returns the value of this {@code Integer} as an
 698      * {@code int}.
 699      */
 700     public int intValue() {
 701         return value;
 702     }
 703 
 704     /**
 705      * Returns the value of this {@code Integer} as a
 706      * {@code long}.

 707      */
 708     public long longValue() {
 709         return (long)value;
 710     }
 711 
 712     /**
 713      * Returns the value of this {@code Integer} as a
 714      * {@code float}.

 715      */
 716     public float floatValue() {
 717         return (float)value;
 718     }
 719 
 720     /**
 721      * Returns the value of this {@code Integer} as a
 722      * {@code double}.

 723      */
 724     public double doubleValue() {
 725         return (double)value;
 726     }
 727 
 728     /**
 729      * Returns a {@code String} object representing this
 730      * {@code Integer}'s value. The value is converted to signed
 731      * decimal representation and returned as a string, exactly as if
 732      * the integer value were given as an argument to the {@link
 733      * java.lang.Integer#toString(int)} method.
 734      *
 735      * @return  a string representation of the value of this object in
 736      *          base 10.
 737      */
 738     public String toString() {
 739         return toString(value);
 740     }
 741 
 742     /**


   1 /*
   2  * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 661     }
 662 
 663     /**
 664      * Constructs a newly allocated {@code Integer} object that
 665      * represents the {@code int} value indicated by the
 666      * {@code String} parameter. The string is converted to an
 667      * {@code int} value in exactly the manner used by the
 668      * {@code parseInt} method for radix 10.
 669      *
 670      * @param      s   the {@code String} to be converted to an
 671      *                 {@code Integer}.
 672      * @exception  NumberFormatException  if the {@code String} does not
 673      *               contain a parsable integer.
 674      * @see        java.lang.Integer#parseInt(java.lang.String, int)
 675      */
 676     public Integer(String s) throws NumberFormatException {
 677         this.value = parseInt(s, 10);
 678     }
 679 
 680     /**
 681      * Returns the value of this {@code Integer} as a {@code byte}
 682      * after a narrowing primitive conversion.
 683      * @jls 5.1.3 Narrowing Primitive Conversions
 684      */
 685     public byte byteValue() {
 686         return (byte)value;
 687     }
 688 
 689     /**
 690      * Returns the value of this {@code Integer} as a {@code short}
 691      * after a narrowing primitive conversion.
 692      * @jls 5.1.3 Narrowing Primitive Conversions
 693      */
 694     public short shortValue() {
 695         return (short)value;
 696     }
 697 
 698     /**
 699      * Returns the value of this {@code Integer} as an
 700      * {@code int}.
 701      */
 702     public int intValue() {
 703         return value;
 704     }
 705 
 706     /**
 707      * Returns the value of this {@code Integer} as a {@code long}
 708      * after a widening primitive conversion.
 709      * @jls 5.1.2 Widening Primitive Conversions
 710      */
 711     public long longValue() {
 712         return (long)value;
 713     }
 714 
 715     /**
 716      * Returns the value of this {@code Integer} as a {@code float}
 717      * after a widening primitive conversion.
 718      * @jls 5.1.2 Widening Primitive Conversions
 719      */
 720     public float floatValue() {
 721         return (float)value;
 722     }
 723 
 724     /**
 725      * Returns the value of this {@code Integer} as a {@code double}
 726      * after a widening primitive conversion.
 727      * @jls 5.1.2 Widening Primitive Conversions
 728      */
 729     public double doubleValue() {
 730         return (double)value;
 731     }
 732 
 733     /**
 734      * Returns a {@code String} object representing this
 735      * {@code Integer}'s value. The value is converted to signed
 736      * decimal representation and returned as a string, exactly as if
 737      * the integer value were given as an argument to the {@link
 738      * java.lang.Integer#toString(int)} method.
 739      *
 740      * @return  a string representation of the value of this object in
 741      *          base 10.
 742      */
 743     public String toString() {
 744         return toString(value);
 745     }
 746 
 747     /**