×

Java Integer toString() method

The toString() method of Java Integer class returns a String object which represents this Integer’s value. The second syntax returns a String object which represents the specified integer. The third syntax returns a string representation of the specified argument in the radix specified by the given radix. Syntax
  • public String toString ()
  • public static String toString (int i)
  • public static String toString (int i, int radix) 
Parameters The parameter ‘i’ represents an integer to be converted to a string and the parameter ‘radix’ represents the radix to use in the string representation. Return Value This method returns a String which represents the same value as this argument in base 10 or in the specified radix. Example 1
public class JavaIntegerToStringExample1 {
    public static void main(String[] args) {
        Integer val=5667;
        String val1=Integer.toString(val);
        //It returns a string representation of the value of this object in base 10.
        System.out.println("String  Value : "+val1);
    }
}
Output
String  Value : 5667
Example 2
public class JavaIntegerToStringExample2 {
    public static void main(String[] args) {
        Integer val=Integer.MAX_VALUE;
        String val1=val.toString();
        //It returns a string representation of the value of this object in base 10.
        System.out.println("String  Value : "+val1);
    }
}
Output
String  Value : 2147483647
Example 3
public class JavaIntegerToStringExample3 {
    public static void main(String[] args) {
        Integer val=566787643;
        int radix=78;
        String val1=Integer.toString(val,radix);
        //It returns a string representation of the value of this object in the     specified radix.
        System.out.println("String  Value : "+val1);
    }
}
Output
String  Value : 566787643
Example 4
public class JavaIntegerToStringExample4 {
    public static void main(String[] args) {
        //passing negative value
        Integer val=-5667;
        String val1=Integer.toString(val);
        System.out.println("Unsigned String  Value : "+val1);
        //calling string class methods
        StringBuffer sf= new StringBuffer(val1);
        StringBuffer reverse=sf.reverse();
        System.out.println("Reverse of "+sf+" : "+reverse);
    }
}
Output
Unsigned String  Value : -5667
Reverse of 7665- : 7665-

Related Topics

Java Integer lowestOneBit()

The lowestOneBit () method of Java Integer class returns an int value with at most a single one-bit, in the position of the lowest-order one-bit in the specified int value.  Syntax public...

2 minutes read.

Java Throw and Throws Keyword

Exceptions in Java enable us to construct high-quality programs where faults are checked at compile time rather than run time and where we may define unique exceptions that make code...

6 minutes read.

Difference Between Data Hiding and Abstraction in Java

Abstraction: Data Abstraction and Data Hiding ideas are utilised to show the expected data to the end client and conceal the superfluous subtleties, however, for specific purposes like decreasing the framework's...

10 minutes read.

ArrayDeque in Java

ArrayDeque The ArrayDeque is one of the essential concepts in java to implement the deque interface. It will allow us to apply a resizable array to implement the Deque interface. This...

8 minutes read.

How to download Eclipse for Java

Introduction: We write a java program, and when we want to run it, we need software to run it. Eclipse is a kind of software used to execute a JavaFX...

3 minutes read.

Java FileOutputStream

What is FileOutputStream?When we need raw stream data written into a file, we need to look for another option: FileOutputStream. It is used when the file's data is byte-oriented. It comes under...

4 minutes read.

How to Convert String to Object in Java

How to Convert String to Object in Java The Object is the super class of all classes. So you can assign a string to Object directly. There are two methods to...

3 minutes read.

Java Tokens

Classes and methods are included in the Java program. The procedures also provide the expressions and statements required to finish a specific operation. Tokens make up the sentences and expressions...

4 minutes read.

Heap Implementation in Java

The root node or parent node of a Java heap is compared to its left and right offspring, and the children are then ordered in line with the comparison.Assuming that...

9 minutes read.

Creating API Document Javadoc tool

The JavaDoc utility is a document generator tool written in Java that generates standard documentation in HTML format. It parses declarations and documentation in a source file collection that describes...

3 minutes read.

Java Math floorDiv() Method

The floorDiv () method of Math class returns the largest integer value that is less than or equal to the algebraic quotient. It firstly divides the dividend and divisor and...

2 minutes read.

Level order Traversal of a Binary Tree in Java

In Java, a level order traversal of a tree structure is also referred to as the breadth-first traversal of the binary tree. Regarding the subsequent binary tree: Level order traversal is as...

5 minutes read.

How to find the length of an Array in Java

Arrays: An array is a sort of container object that stores constant quantities of values of a single type in one memory area. A finite number of items must all be...

3 minutes read.

Practical Number in Java

In this tutorial, we will understand what is meant by practical numbers. We will understand it throughthe aid of examples and implementation in a java programming language. The practical numbers...

5 minutes read.

Java.net.ConnectionException

java.net.ConnectException: Connection rejected: the interface is the most continuous sort of happening, organizing special cases in Java at whatever point the product is in client-server engineering and attempting to make...

3 minutes read.

Prime Number Program in Java

Prime Number Program in Java using for loop A natural number which is greater than 1 and has only two factors the number itself and 1 is called prime number. In...

2 minutes read.

Mutable class in Java

A language for object-oriented programming is Java. Because this is an object-oriented language of programming, all of its mechanisms and methods are based on objects. Java has a concept of...

6 minutes read.

How to Assign Static Value to Date in Java?

In this tutorial, we will learn certain ways to assign a static value to a date in java. We will see the limitation of each method that will lead to...

3 minutes read.

Java Network Programming (Socket Programming in Java)

JAVA NETWORK Network programming is used to execute programs across multiple machines that are connected by a network. The java.net package contains a collection of classes and interfaces that provide this...

3 minutes read.

Java Enumeration

In a computer language, enumerations express a set of named constants. For instance, the four suits in a deck of playing cards could be represented by the enumerators Club, Diamond,...

4 minutes read.