Java – Convert Integer to String

In Java, you can use String.valueOf() to convert an Integer to String.

1. String.valueOf

1.1 Example to convert an Integer or int 10 to a String.


	Integer num = 10;
	//int num = 10;
	
	String numInString = String.valueOf(num);

	System.out.println(numInString);

Output


10

2. toString()

It works on Integer object only.


	Integer num = 10;

	String numInString = num.toString();

	System.out.println(numInString);

Output


10

2.2 For primitive type int, try Integer.toString()


	int num = 10;

	String numInString = Integer.toString(num);

	System.out.println(numInString);

Output


10

References

No comments yet. Be the first to leave a comment!

Leave a Comment

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