×

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

Bully Algorithm code in Java

Election algorithms include the bully algorithm, mainly used to select a coordinate. To find a coordinator in a distributed system that can carry out the tasks required by other processes,...

4 minutes read.

Java List Node

In Java, List Node is the same as the single linked list, which is the collection of nodes. So, we can say, the list nodes are grouped together to get...

8 minutes read.

Dangling Else problem in Java

A language interpretation uncertainty is the hanging other issue. The following two types of condition executed code are both possible in programming: 1. if-then-else form 2. if-then form When dealing with the nested...

3 minutes read.

How to convert String to String array in Java

A String in Java is a thing that indicates a collection of letters. We must include the String class from java.lang package if we want to be using strings. An...

5 minutes read.

Java Open File

Java Desktop class give an open() strategy to open a filr. It has a place with a java.awt package. Work area execution is stage subordinate, so it is important to...

5 minutes read.

How to Solve the Deprecated Error in Java?

Deprecated Java methods should not be used because they are deprecated (often, there are better, more modern alternatives). API update. Until now, Java has kept everything backward compatible and never...

3 minutes read.

Java Byte Keyword

Byte: The Keyword Byte in Java programming language is a primitive data type.Digital content that is most used for eight bits is called as a byte.The Java Byte Keyword is used...

3 minutes read.

Java 9 Interface Private Method

Java 9 provides us the facility to include private methods inside the java interface. In java 8 and earlier versions, we are supposed to use only constant variables and abstract...

3 minutes read.

Java Program to print even and odd numbers using 2 threads

Using two threads in a single thread is even odd printing in Java programming with multiple threads. To create code that prints even and odd using two threads, we must...

2 minutes read.

Types of Logical Operators in Java

In this tutorial, we are going to study logical operators. A logical operator is an operator that accomplishes a logical operation that is to connect two or more operations. These...

5 minutes read.

java.lang.NumberFormatException for Input String

java.lang.NumberFormatException for Input String The exception java.lang.NumberFormatException for input string occurs when we try to convert a string into a number format. For example, if someone converts the string “Tutorial & Example”...

3 minutes read.

Lazy Propagation in Segment Tree in Java

The topic of segment trees in Java is continued by the topic of sluggish propagation in segment trees. It is suggested that readers first read through the section tree topic....

4 minutes read.

Different Ways to Print Exception Message in Java

In this section, we will learn how to use various Java Throwable class methods to print exception messages. The Throwable class has the three methods listed below for printing the...

4 minutes read.

Java vs Dot Net

Java : Java is a pure object oriented language. It was introduced by James Gosling in the year 1995. The first public implementation of java was done by sun micro systems...

3 minutes read.

Java Math floor() Method

The floor() method of Math class returns the largest double value that is equal to a mathematical integer and is less than or equal to the argument. Syntax: public static double floor(double...

2 minutes read.

Object class in Java

In Java, a class is a file containing the Java byte code. It can essentially specifically be executed on the JVM (Java Virtual Machine), fairly significant. The JVM mostly generally...

6 minutes read.

Rotate matrix by 90 degrees in Java | Rotate matrix in Java clockwise and anti-clockwise

In this article, you will be acknowledged about what is a matrix along with an example. Most importantly you will be equipped knowledge on how to rotate the matrix by...

4 minutes read.

Zigzag Traversal of Binary Tree in Java

In this article, you will be acknowledged about the zigzag traversal of binary tree in java and the approaches or ways in which the zigzag traversal can be done. Zigzag Traversal A...

10 minutes read.

Scanner in Java

Static way of Programming: When a variable can’t change its value during run time is called a Static way of programming. In this programming a variable is directly assigned to a...

4 minutes read.

Command Class in Java

We use the command class to run commands against the database. The Command class may find a set of parameter objects for use in sending values to a stored procedure...

3 minutes read.