This post provides different ways to convert a String to a long or Long in Java, including using Long's constructor, Long.valueOf(), Long.parseLong(), Long.decode(), Apache Commons' NumberUtils.createLong(), Long.parseUnsignedLong(), and Google Guava's Longs.tryParse(). It also mentions that parseLong() is the preferred approach to obtain a long primitive, while valueOf() is the preferred approach to obtain a Long object from a String.
Table of contents
1. Overview2. Using Long ‘s Constructor3. Using the Long.valueOf() Method4. Using the Long.parseLong() Method5. Using the Long.decode() Method6. Using Apache Commons’ NumberUtils.createLong() Method7. Using the Long.parseUnsignedLong() Method8. Using Google Guava’s Longs.tryParse() Method9. ConclusionSort: