I will add another answer, which is the fastest possible Χ (yes, even more than the accepted answer), but it will not work for each individual case. HOWEVER, it will work for every conceivable scenario:
You can simply use String as an intermediate. Please note that this will give you the correct result, even if it seems that using String may lead to incorrect results. HOW LONG, HOW YOU KNOW, YOU WORK WITH "NORMAL" STRINGS. This is a method of increasing efficiency and simplifying the code, which in turn should use some assumptions for the rows of data on which it works.
Con when using this method:. If you are working with some ASCII characters, such as these characters at the beginning of the ASCII table, the following lines may fail, but let them come across this - you will probably never use them anyway.
About using this method: Remember that most people usually work with some normal lines without any unusual characters, and then the method is the easiest and fastest way.
from Long to byte []:
byte[] arr = String.valueOf(longVar).getBytes();
from byte [] to Long:
long longVar = Long.valueOf(new String(byteArr)).longValue();
Yonatan Nir Nov 14 '15 at 10:20 2015-11-14 10:20
source share