Table of contents
1.
Introduction
2.
How to Convert int to String in Java?
2.1.
String.valueOf()
2.2.
Java
2.3.
Integer.toString()
2.4.
Java
2.5.
String.format()
2.6.
Java
2.7.
DecimalFormat class
2.8.
Concatenation Using Empty String
3.
Frequently Asked Questions
3.1.
What is the purpose of the valueOf()` method in Java?
3.2.
How many primitive data types are present in Java?
3.3.
What are the three most commonly used methods for int to String conversion?
3.4.
Why do we need to convert an int to a String?
3.5.
What are primitive data types?
4.
Conclusion
Last Updated: Jun 6, 2025
Medium

Int to String Conversion in Java

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Java is an object-oriented, class-based, high-level programming language. It is based on the concept of WORA (write once use anywhere) for developer ease. Java classes are compiled into byte code. The compiled byte codes can be used on any platform supporting Java without recompiling the class.

”int to string jav

We have eight primitive or native data types in Java, namely,

  • int
  • short
  • long
  • byte
  • float
  • double
  • boolean
  • char

We also have the option of multiple non-primitive data types in Java. The String is one of Java's most commonly used non-primitive data types. And there often arises the need to convert int to String in Java.

How to Convert int to String in Java?

In Java, you can convert an int to a String using methods like String.valueOf(int) or Integer.toString(int).
These methods convert the numeric value into its string representation without manual concatenation.

String.valueOf()

The String.valueOf function is the most commonly used function for the conversion of int to String in Java. The valueOf method belongs to the String class and is a static method. Let us look at the syntax for the same,

Syntax

String s=String.valueOf(i);

Java int to String Example using String.valueOf()

  • Java

Java

The complete code will look like this,
class int_to_string{
public static void main(String [] args){
int number = 50;
String string_number = String.valueOf(number);
System.out.println("This is the Integer value + 100: "+ (number+100));
System.out.println("This is the String value + 100: "+ string_number+100);
}
}
You can also try this code with Online Java Compiler
Run Code

 

In the above code, we have the integer to string in Java conversion using String.valueOf() function. 100 gets added to the integer value, whereas it gets concatenated with the string value, thus producing different results and depicting the conversion from int to string in Java.

Integer.toString()

The Integer.toString function is also a widely used function for converting int to String in Java. The toString method belongs to the String class and is a static method. Let us look at the syntax for the same,

Syntax

String s = Integer.toString(i);

Java int to String Example using Integer.toString()

  • Java

Java


class int_to_string{
public static void main(String [] args){
int number = 50;
String string_number = Integer.toString(number);
System.out.println("This is the Integer value + 100: "+ (number+100));
System.out.println("This is the String value + 100: "+ string_number+100);
}
}
You can also try this code with Online Java Compiler
Run Code

In the above code, we have the integer to string in Java conversion using Integer.toString() function.  100 gets added to the integer value, whereas it gets concatenated with the string value, thus producing different results and depicting the conversion from int to string in Java.

String.format()

The String.format method is used to format a given Data type to the String Data type using its String format. Let us look at an example for conversion of int to string in Java using String.format(),

Syntax

class int_to_string{
You can also try this code with Online Java Compiler
Run Code

Java int to String Example using String.Format()

  • Java

Java

public static void main(String [] args){
int number = 50;
String string_number = String.format("%d",number);
System.out.println("This is the Integer value + 100: "+ (number+100));
System.out.println("This is the String value + 100: "+ string_number+100);
}
}
You can also try this code with Online Java Compiler
Run Code

In the above code, we have the integer to string in Java conversion using String.format() function.  100 gets added to the integer value, whereas it gets concatenated with the string value, thus producing different results and depicting the conversion from int to string in Java.

Try it by yourself on Java Online Compiler.

DecimalFormat class

The DecimalFormat class is used to format numbers into strings with a specific pattern. It’s useful for formatting numeric values in custom string formats.

Syntax:

DecimalFormat formatter = new DecimalFormat("pattern");
String string_number = formatter.format(number);
You can also try this code with Online Java Compiler
Run Code


Java int to String Example using DecimalFormat

import java.text.DecimalFormat;

public class IntToStringExample {
    public static void main(String[] args) {
        int number = 50;
        DecimalFormat formatter = new DecimalFormat("###");
        String string_number = formatter.format(number);
        System.out.println("This is the Integer value + 100: " + (number + 100));
        System.out.println("This is the String value + 100: " + string_number + 100);
    }
}
You can also try this code with Online Java Compiler
Run Code

Concatenation Using Empty String

By adding an empty string ("") to an integer, Java automatically converts the integer to a string.

Syntax:

String string_number = number + "";
You can also try this code with Online Java Compiler
Run Code


Java int to String Example using Concatenation

public class IntToStringConcat {
    public static void main(String[] args) {
        int number = 50;
        String string_number = number + "";
        System.out.println("This is the Integer value + 100: " + (number + 100));
        System.out.println("This is the String value + 100: " + string_number + 100);
    }
}
You can also try this code with Online Java Compiler
Run Code

Frequently Asked Questions

What is the purpose of the valueOf()` method in Java?

The valueOf() method in Java converts a given data type, like int or String, into its corresponding wrapper class object, such as Integer or Double.

How many primitive data types are present in Java?

We have eight primitive or native data types in Java: int, short, long, byte, float, double, boolean, and char.

What are the three most commonly used methods for int to String conversion?

The three most commonly used methods in Java for the conversion of int to String are: String.valueOf(), “data_type”. toString(), String.format().

Why do we need to convert an int to a String?

The need for int to String conversion arises when the developers are provided with such huge numbers that they cannot be stored in the primitive Data types in Java.

What are primitive data types?

In computer programming, Primitive Data types are the set of variable types from which all the other data types are derived.

Conclusion

Converting an int to a String in Java is simple and can be done using several methods like String.valueOf(), Integer.toString(), String.format(), DecimalFormat, or even by concatenating with an empty string. Each method is useful depending on the situation—whether you need performance, formatting, or simplicity. 

Check out this problem - Multiply Strings

Recommended Readings:

Live masterclass