Fastest way to get the first n elements of a List into an Array

后端 未结 5 1978
囚心锁ツ
囚心锁ツ 2020-12-30 20:51

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

        
5条回答
  •  暖寄归人
    2020-12-30 21:19

    It mostly depends on how big n is.

    If n==0, nothing beats option#1 :)

    If n is very large, toArray(new String[n]) is faster.

提交回复
热议问题