Advertisement
DulcetAirman

int[] to List<Integer>

Dec 18th, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. package ch.claude_martin.playground;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.stream.Collectors;
  6.  
  7. public class SomeClass {
  8.  
  9.     public static void main(String[] args) {
  10.         int[] a = { 1, 2, 3, 4 };
  11.         List<Integer> list = toList(a);
  12.         System.out.println(list);
  13.     }
  14.  
  15.     public static List<Integer> toList(int[] a) {
  16.         return Arrays.stream(a).mapToObj(Integer::valueOf).collect(Collectors.toList());
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement