java tutorial - How to Convert int to string in java - java programming - learn java - java basics - java for beginners



 int to str

Learn Java - Java tutorial - int to str - Java examples - Java programs

Java Convert int to string

  • The String.valueOf() method converts int to String.
  • The valueOf() is the static method of String class.
  • This is also an efficient solution like the first option above.
  • And because this is simple and efficient, it is also a very popular method for converting an int to String.

Syntax:

using Integer.toString()

sample code:

public class int_to_str {
  public static void main(String[] args) {
    int val= 916;
    String str = Integer.toString(val);
    System.out.println(str);
  }
}

Output:

         916

Syntax:

using String.valueOf()
 int to str1

Learn Java - Java tutorial - int to str1 - Java examples - Java programs

sample code:

public class int_to_str {
       public static void main(String args[]){
        int i=123;
        String s=String.valueOf(i);
        System.out.println(i+100); 
        System.out.println(s+100);
    }
}

Output:

                                           223
                                             123100

Related Searches to how to Convert int to string in java