Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thospfuller/d5652f571c252cbe329d65f2e9bbb685 to your computer and use it in GitHub Desktop.
Save thospfuller/d5652f571c252cbe329d65f2e9bbb685 to your computer and use it in GitHub Desktop.
How To Convert An Array To An ArrayList In Java using Java Streams (example two).
import java.util.stream.Collectors;
import java.util.List;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
List<Integer> exampleList =
Arrays
.stream(numbers)
.boxed()
.collect(
Collectors.toList()
);
System.out.println ("exampleList.getClass (): " + exampleList.getClass ());
exampleList.forEach (item -> System.out.println ("item: " + item));
System.exit (0);
}
}
@thospfuller
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment