dimanche 19 mai 2019

Java : Convert Array to ArrayList

Before Java 8 :

List targetList = new ArrayList(Arrays.asList(sourceArray));

Apache Commons Collections : 

Personne[] sourceArray = { P0, P1, P2, P3, P4, P5 };
List targetList = new ArrayList<>(6);
CollectionUtils.addAll(targetList, sourceArray);

After Java 8 : 

List<PersonnetargetList = Arrays.stream(sourceArray).boxed().collect(Collectors.toList());

Aucun commentaire:

Enregistrer un commentaire

to criticize, to improve