Last active
October 18, 2023 16:31
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the following article: How To Convert An Array To An ArrayList In Java!