How to convert a String to a long in Java?
The Long class contains a number of (static) methods for converting to/from various formats. To convert to a long use static method Long.parseLong() String s = "123"; try { long l = Long.parseLong(s);...
View ArticleHow to convert a long to a String in Java?
Use static method Long.toString() long l = 123L; String s = java.lang.Long.toString(l); // An alternative would be to // use the following string concatenation String s2 = "" + l;
View ArticleHow to convert a long to a byte array
The following code can be used to extract the 8 bytes from a long value and return them as a byte array public static byte[] longToByteArray(long data) { return new byte[] { (byte)((data >> 56)...
View ArticleHow to convert byte array to long
The following code can be used to convert a byte array (containing the bytes of a long) into a long. public static long byteArrayToLong(byte[] bytes) { long l = 0; for (int i=0; i<8; i++) { l...
View Article