We can convert Java Long to String using the following methods:
- String.valueOf() method
- Long.toString() method
Convert Java Long to String using the String.valueOf() method
There are multiple overloaded versions of the valueOf() method from the String class. We will use the one which accepts long.
Example
class Test { public static void main(String[] args) { String s1 = String.valueOf(1299491103L); String s2 = String.valueOf(1828319L); String s3 = String.valueOf(120113L); System.out.println(s1); System.out.println(s2); System.out.println(s3); } }
Output: 1299491103 1828319 120113
Parse Long to String using the Long.toString() method
We can also use the static method toString() of the Long class. It returns a String representation of a provided long.
Example
class Test { public static void main(String[] args) { String s1 = Long.toString(1299491103L); String s2 = Long.toString(1828319L); String s3 = Long.toString(120113L); System.out.println(s1); System.out.println(s2); System.out.println(s3); } }
Output: 1299491103 1828319 120113
Happy coding!