Skip to content

Instantly share code, notes, and snippets.

@RICH0423
Created February 2, 2018 06:07
Show Gist options
  • Save RICH0423/f82730de0aeaa076b041443735a49f38 to your computer and use it in GitHub Desktop.
Save RICH0423/f82730de0aeaa076b041443735a49f38 to your computer and use it in GitHub Desktop.
Program to Convert 'int' Array to 'List' of Integer
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Array2ListDemo {
public static void main(String[] args) {
/**** Converting a Primitive 'int' Array to List ****/
int intArray[] = {1, 2, 3, 4, 5};
List<Integer> integerList1 = Arrays.stream(intArray).boxed().collect(Collectors.toList());
System.out.println("List #1: " + integerList1);
/**** 'IntStream.of' or 'Arrays.stream' Gives The Same Output ****/
List<Integer> integerList2 = IntStream.of(intArray).boxed().collect(Collectors.toList());
System.out.println("List #2: " + integerList2);
/**** Converting an 'Integer' Array to List ****/
Integer integerArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
List<Integer> integerList3 = Arrays.stream(integerArray).collect(Collectors.toList());
System.out.println("List #3: " + integerList3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment