How to convert int to String in Java.

October 4, 2016

To convert int to String in Java you can use:

1. Integer.toString(int i) method:

The String method takes Integer.toString(int s) an int as an argument and returns a String object.

This example uses Integer.toString(int i) to convert int to String. Result of above code is:

2. String.valueOf(int i) method:

The String method takes String.valueOf(int s) an int as an argument and returns a String object.

In above example, we’re using String.valueOf(int i) to convert int to String. The last line will print:

3. String concatenation:

You can just add int to empty string, its returns a String object;

The example above convert primitive integer value to String object using String concatenation. Below is the output of the above code:
Click here to add a comment

Leave a comment: