This sadly doesn't work:
long[] longs = new long[]{1L};
ArrayList<Long> longArray = new ArrayList<Long>(longs);
Is there a nicer way except adding them manually?
Using ArrayUtils from apache commons-lang
long[] longs = new long[]{1L};
Long[] longObjects = ArrayUtils.toObject(longs);
List<Long> longList = java.util.Arrays.asList(longObjects);
Since others have suggested external libraries, here's the Google Guava libraries way:
long[] longs = {1L, 2L, 3L};
List<Long> longList = com.google.common.primitives.Longs.asList(longs);
Relevant javadoc for Longs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With