This may be a bit of an easy, headdesk sort of question, but my first attempt surprisingly completely failed to work. I wanted to take an array of primitive longs and turn it into a list, which I attempted to do like this:
long[] input = someAPI.getSomeLongs();
List<Long> inputAsList = Arrays.asList(input); //Total failure to even compile!
What's the right way to do this?
Since Java 8 you can now use streams for that:
If you want similar semantics to
Arrays.asList
then you'll need to write (or use someone else's) customer implementation ofList
(probably throughAbstractList
. It should have much the same implementation asArrays.asList
, only box and unbox values.No, there is no automatic conversion from array of primitive type to array of their boxed reference types. You can only do