Pensé que podría extrapolar de esta pregunta pero no puedo
Por supuesto que puedo hacer
short[] shortarray = {0,1,2};
List<Short> shortList = new ArrayList<Short>();
for (Short s : shortarray) {
shortList.add(s);
}
Pero me pregunto cómo hacerlo con transmisiones.
List<Short> shortList = Arrays.stream(shortarray).boxed()
.collect(Collectors.toList());
no funciona, por ejemplo, pero produce The method stream(T[]) in the type Arrays is not applicable for the arguments (short[])
fuente
mapToObj
y nomapToInt
(o simplemap
)? usar un enIntStream
lugar deStream<Integer>
debería ser preferible en casi todas las situaciones en las que se manejan entradas primitivas o cortos.mapToInt
finalmente recoger unaList<Integer>
instancia, no unList<Short>
.List<Short>
, por lo que no se puede evitar el boxeo.List<Short>
. No es que alguna vez encontré tal necesidad en la vida real ...