Most examples i see here explain how to convert an array of primitives to ArrayList.
Is it possible to use stream() to convert an array of non-primitives into an ArrayList?
If not, is there a utility to do the same ?
Most examples i see here explain how to convert an array of primitives to ArrayList.
Is it possible to use stream() to convert an array of non-primitives into an ArrayList?
If not, is there a utility to do the same ?
The trivial answer is of course:
String[] array = ...;
List<String> list = List.of(array);
You mention 'use stream()' - um, why? Stream is a tool. For this job, that's a bit like asking: "Hey, can I hammer in a nail.... using a shoe?". I guess, maybe? Shoes are great if you're going for a run, not appropriate when trying to fasten a nail. Use a hammer.
But if you want to.. sure.. Arrays.stream(array).collect(Collectors.toList());
, but this is more typing, slower, less idiomatic, and basically in all ways worse.