Java Integer toString() Method25 Mar 2025 | 3 min read The toString() method of Java Integer class is used to get a String object representing the value of the Number Object. There are three different types of Java toString() method which can be differentiated depending on its parameter. These are:
1. Java Integer toString() MethodThe toString() method of Java Integer class returns a string equivalent of this Integer's value. This method gives the same result as Integer.toString(int i). It overrides the toString() method of class Object. 2. Java Integer toString(int i) MethodThe toString(int i) is an inbuilt method of Java which is used to return a String object representing the specified integer in the method argument. 3. Java Integer toString(int i, int radix) MethodThis method returns a string representation of the first int type argument in the radix specified by the second argument. If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX then the base 10 is used. In this method, the following ASCII characters are used as digits: 0 to 9 and a to z. Note: If the first argument is negative, the result of the first element is the ASCII minus character '-'.Syntax:Following is the declarations of toString() method: Parameter:
Returns:
Exceptions:NA Compatibility Version:Java 1.0 and above Example 1Output: String Representation = 25 String Representation = -18 Example 2Output: Output: -12 Output: 12 Example 3Output: Enter Number to be string representation : -3465.876 Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at myPackage.IntegerToStringExample3.main(IntegerToStringExample3.java:10) Example 4Output: String Value = 65 String Value = 41 String Value = 101 String Value = 1000001 Example 5Output: Enter Inputs to be string representation: Enter Number: -45648 Enter Radix/Base: 16 Output: -b250 Next TopicJava-integer-tounsignedlong-method |
Java Method The toUnsignedLong() is a Java Integer class method which converts the argument to a long by an unsigned conversion. In an unsigned conversion to a long, the high-order 32 bits of the long are zero and the low-order 32 bits are equal to...
2 min read
Java Method The remainderUnsigned() method is a method of Java Integer class which returns the unsigned remainder of dividing the first argument by the second argument where each argument and the result is interpreted as an unsigned value. Syntax: Following is the declaration of remainderUnsigned() method: public static...
2 min read
Java Method The numberOfTrailingZeros() method is a method of Integer class under java.lang package. This method returns the total number of zero bits following the lowest-order ("rightmost") one's-bit in the two's complement binary representation of the specified integer value i.e. it converts int value to...
2 min read
Java Method The hashCode() method is a Java Integer class method which returns the hash code for the given inputs. There are two different types of Java hashCode() method which can be differentiated depending on its parameter. These are: Java Method Java Integer hashCode(int value) Method hashCode()...
3 min read
Java Method The rotateRight() method of Java Integer class returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits. (Bits shifted out of the right hand, or low-order). Bit shifting is a bitwise...
3 min read
Java Method The parseUnsignedInt() is a method of Java Integer class. There are three different types of parseUnsignedInt() method which can be differentiated depending on its parameter. These are: Java Integer parseUnsignedInt (String s) Method Java Integer parseUnsignedInt (String s, int radix) Method Java Integer parseUnsignedInt (CharSequence s, int...
5 min read
Java Method The reverse() method of Java Integer class numerically returns the value obtained by reversing the order of the bits in the 2's complement binary representation of the specified integer value. Syntax: Following is the declaration of reverse() method: public static int reverse(int i) Parameter: DataType Parameter Description Required/Optional int i Integer value whose bits...
2 min read
Java Method The toBinaryString() method of Java Integer class returns a string representation of the integer argument as an unsigned integer in binary base 2. Note: If the argument is snegative, the unsigned integer value is the argument plus 232otherwise, it is equal to the argument....
2 min read
Java method The compare() method is a method of Integer class under java.lang package. This method compares two integer values numerically. It returns the result in integer equivalent value by comparing the two int method arguments. The value returned is identical to what would be...
2 min read
The Java Integer class comes under the Java.lang.Number package. This class wraps a value of the primitive type int in an object. An object of Integer class contains a single field of type int value. Java Integer Methods The Java Integer class provides several methods for converting...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India