Name

Integer

Synopsis

This class provides an immutable object wrapper around the int primitive data type. This class also contains useful minimum and maximum constants and useful conversion methods. parseInt( ) and valueOf( ) convert a string to an int or to an Integer, respectively. Each can take a radix argument to specify the base the value is represented in. decode( ) also converts a String to an Integer. It assumes a hexadecimal number if the string begins with “0X” or “0x”, or an octal number if the string begins with “0”. Otherwise, a decimal number is assumed. toString( ) converts in the other direction, and the static version takes a radix argument. toBinaryString( ) , toOctalString( ), and toHexString( ) convert an int to a string using base 2, base 8, and base 16. These methods treat the integer as an unsigned value. Other routines return the value of an Integer as various primitive types, and, finally, the getInteger( ) methods return the integer value of a named property from the system property list, or the specified default value.

Java 5.0 adds a number of static methods that operate on the bits of an int value. rotateLeft( ) and rotateRight( ) shift the bits the specified distance in the specified direction, with bits shifted off one end being shifted in on the other end. signum( ) returns the sign of the integer as -1, 0, or 1. highestOneBit( ) , numberOfTrailingZeros( ), bitCount( ) and related methods can be useful if you use an int value as ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.