OneBite.Dev - Coding blog in a bite size

convert variable from int to string in java

Code snippet on how to convert variable from int to string in java

int myInt = 10;
String myString = Integer.toString(myInt);

This code converts an integer variable to a string variable. The first line declares a variable “myInt” of type integer and assigns it the value of 10. The second line declares a variable “myString” of type string. We then use the Integer class’ toString() method which takes in our integer value (myInt) and returns a string representation of it, which is then assigned to the “myString” variable.

java