What is the fastest way to get the first n elements of a list stored in an array?
Considering this as the scenario:
int n = 10;
ArrayList
Assumption:
list - List
Using Java 8 Streams,
to get first N elements from a list into a list,
List
to get first N elements from a list into an Array,
String[] firstNElementsArray = list.stream().limit(n).collect(Collectors.toList()).toArray(new String[n]);