Home » Java programs » Java conversion programs

Conversion from Long to String in Java

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

Given a long value and we have to convert it into string.

Java conversion from Long to String

To convert a Long to String, we use toString() method of Long class, it accepts a long value and returns the string value.

Syntax:

    Long.toString(long);

Java code to convert a Long to String

//Java code to convert along to String
public class Main {
    public static void main(String args[]) {
        long a = 112120;
        long b = 2121210;

        //variable to store result
        String result = null;

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

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

Output

result (value of a as string) = 112120
result (value of b as string) = 2121210




Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.