0 votes
75 views
in Java by
How to convert integer to string in java? This is needed for my live application. Anybody can help me.

1 Answer

0 votes
by
There are various way to convert integer to string:
package com;

public class IntegerToStringConversion {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Integer intgerNum = 100;
        String stringNum = intgerNum + "";//It uses more memory
        System.out.println("Integer Num: " + intgerNum + " String Num: " + stringNum);
        String stringNum1 = String.valueOf(intgerNum);//I prefer this
        System.out.println("Integer Num: " + intgerNum + " String Num: " + stringNum1);
        String stringNum2 = Integer.toString(intgerNum);//And this is also fine
        System.out.println("Integer Num: " + intgerNum + " String Num: " + stringNum2);
    }

}

Output:
Integer Num: 100 String Num: 100
Integer Num: 100 String Num: 100
Integer Num: 100 String Num: 100

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...