爱问知识人 爱问教育 医院库

List中的toArray()怎么使用?

首页

List中的toArray()怎么使用?

List中的toArray()怎么使用?

提交回答

全部答案

    2017-07-27 19:47:31
  •   在程序中,往往得到一个List, 程序要求对应赋值给一个array, 可以这样写程序,for example:
    Long[] l = new Long[list。size()];
    for(int i=0;i]; list。toArray(l);
    2。
       Long[] l = (Long[]) list。toArray(new Long[0]); 3。 Long[] a = new Long[]; Long[] l = (Long[]) list。toArray(a); ----------------------------------------------------------------- java sdk doc 上讲: public Object[] toArray(Object[] a) a--the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose。
       如果这个数组a足够大,就会把数据全放进去,返回的数组也是指向这个数组;要是不够大,就申请一个跟参数同样类型的数组,把值放进去,然后返回。

    F***

    2017-07-27 19:47:31

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):