Convert <Objct> list to <Id> array in java 8 thread
So I have a user class
User{
id
name
}
& I need to convert List<User>
to Array using a stream, so one of the ways I do is convert to a list and then to an array
coll.stream().map(am -> am.getId())
.collect(Collectors.<Integer>toList())
.toArray(new Integer[0])
but I think there should be a different approach to direct conversion to an array, rather than adding to a list and then converting to an array.
+4
2 answers