首页 > 编程语言 > 详细

Java Q & A

时间:2016-08-21 10:56:04      阅读:151      评论:0      收藏:0      [点我收藏+]

1. What is the difference between

i.  List<Integer> list1 = new ArrayList<Integer>(Arrays.asList(ia));
ii. List<Integer> list2 = Arrays.asList(ia); 
i.  new ArrayList<Integer>(Arrays.asList(ia))
  • The new ArrayList is an independent copy of the original one.
  • Although you create the wrapper using Arrays.asList, it is used only during the construction of the new ArrayList and is garbage-collected afterwards.
ii. Arrays.asList(ia)
  • Array ia and creates a wrapper that implements List<Integer>, which makes the original array as a list.
  • Nothing is copied at all, only a single wrapper object is created.
  • Operations on the list wrapper are propagated to the original array -- if you shuffle the list wrapper, the original array is shuffled; if you overwrite an element, it gets overwritten in the original array, etc.
  • Some List operations aren‘t allowed on the wrapper, like adding or removing elements from the list -- no resize.
  • list wrapper doesn‘t extend ArrayList -- ArrayLists have their own, internal array, which they are able to resize. 

 

2.

Java Q & A

原文:http://www.cnblogs.com/joycelee/p/5792235.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!