How to Convert int to String in Java

This post shows several ways to convert int to String in Java.

Convert using Integer.toString() method

Wrapper class Integer has a toString() method that returns a String object representing the passed integer. Using this method you can convert int to String in Java.

Example code

Output

Convert using String.valueOf() method

String.valueOf(int i) – Returns the string representation of the int argument.

Example code

Output

Converting using String concatenation

You can concatenate the int value with an empty string (“”) that will return the result as a String.

Example code

Output

Converting using append method of StringBuilder or StringBuffer class

Both StringBuilder and StringBuffer classes have append() method where you can pass int as an argument. The append() method will append the string representation of the int argument to the sequence.

Example code using StringBuilder

Output

That’s all for the topic How to Convert int to String in Java. If something is missing or you have something to share about the topic please write a comment.


You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.