3 examples of Java int to string conversion by valueOf and toString methods

The int to string conversion in Java

In the previous chapter, we learned how to convert strings to int data type in Java. You can also convert an int to a string by using the built-in methods provided by Java. These methods are explained below with examples.

Using Java valueOf method of String

You can use the valueOf method of String object to convert an int to string in Java. In the following example, you can see how we can use that.

Syntax of valueOf method

String.valueOf(int);

Following example shows how to use the valueOf method for converting Java int to string.

Experience this online

The output will be:

string to int example: 50

Using toString method of Integer

You may also use the toString method of Integer to convert an int to string. See an example below to learn how to use it.

Syntax of using the toString method

Integer.toString(int);

Java toString method to convert an integer to string example

Following example shows how to use the toString method to convert an int to string.

Experience this online

The output will be:

int to string example: 50

Using + operator to convert int to string

The simplest way is to use a + operator to convert an int to string. See the example below.

Experience this online

The output will be:

A string to int example: 50

Related reading: string to int conversion | Java double to int