Wednesday, July 20, 2016

Another way to convert an int to String

import java.util.Scanner;
public class IntToStrMethodsDemo {
    public static void main(String[] args) {
        int num;
        String str=intToStr(num);
    public static int readInt(){
        System.out.println("enter an int");
        return new Scanner(;
    public static String intToStr(int num){
        return ""+num;

Or use the code below :

String str = ""+new Scanner(;

It does the same

Saturday, July 16, 2016

Simple utility to convert an int to String

package utilities;
import java.util.Scanner;
public class IntToStr {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(;
        System.out.println("Enter an integer :");
        int num = scanner.nextInt();
        String str = intToStr(num);
        System.out.println("number String : "+str);
    public static String intToStr(Integer num){
        return num.toString();