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<String> in = new ArrayList<>();
for(int i = 0; i < (n+10); i++)
in.add("foobar");
Option 1:
String[] out = new String[n];
for(int i = 0; i< n; i++)
out[i]=in.get(i);
Option 2:
String[] out = (String[]) (in.subList(0, n)).toArray();
Option 3: Is there a faster way? Maybe with Java8-streams?