Java Int to String

  • + 0 comments

    "int" is a primitive data type. "String" is a class.

    So,to convert integer to a string,it should be a object. Convert "int" to "Integer" as follows.

       int n = sc.nextInt();
       Integer i = new Integer(n);
    

    Now "Integer" and "String" are classes.We can convert Integer to String using "toString()".

    String s = i.toString();