How to convert long to string android studio - java

https‮//:‬www.lautturi.com
How to convert long to string android studio - java

To convert a long to a String in Android Studio (Java), you can use the Long.toString method or the String.valueOf method.

Here is an example of how you can use the Long.toString method to convert a long to a String in Android Studio:

long l = 42;
String s = Long.toString(l);

This code defines a long variable called l and assigns it the value 42, and then converts it to a String using the Long.toString method and stores the result in a String variable called s.

You can also use the String.valueOf method to achieve the same result, like this:

long l = 42;
String s = String.valueOf(l);

This code defines a long variable called l and assigns it the value 42, and then converts it to a String using the String.valueOf method and stores the result in a String variable called s.

Both of these approaches will create a String object with the same value as the long variable.

Note that in Java, the long primitive type and the String class are not the same thing. The long primitive type is a primitive data type that represents a 64-bit signed integer, while the String class is an object that represents a sequence of characters.

You can use the String class to manipulate text data in various ways, such as concatenating strings, searching for substrings, and formatting strings. However, the String class is generally slower than the long primitive type, so it is usually more efficient to use the long primitive type whenever possible.

Created Time:2017-11-01 12:04:59  Author:lautturi