×

Java Programs

Java Practice

Conversion from Integer to String in Java

Java conversion from Integer to String: Here, we are going to learn how to convert a given Integer value to string in Java?
Submitted by IncludeHelp, on July 15, 2019

Problem statement

Given an integer and we have to convert it into string.

Java conversion from Integer to String

To convert an Integer to String, we use toString() method of Integer class, it accepts an integer value and returns the string value.

Syntax

Integer.toString(int);

Java program to convert an Integer to String

//Java code to convert an Integer to String
public class Main {
    public static void main(String args[]) {
        int a = 10;
        int b = 20;

        //variable to store result
        String result = null;

        //converting integer to string
        result = Integer.toString(a);
        System.out.println("result (value of a as string) = " + result);

        result = Integer.toString(b);
        System.out.println("result (value of b as string) = " + result);
    }
}

Output

result (value of a as string) = 10
result (value of b as string) = 20

Java Conversion Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.