打字猴:1.700444249e+09
1700444249 new SubList<E>(this, fromIndex, toIndex));
1700444250
1700444251 }
1700444252
1700444253 subList方法是由AbstractList实现的,它会根据是不是可以随机存取来提供不同的SubList实现方式,不过,随机存储的使用频率比较高,而且RandomAccessSubList也是SubList子类,所以所有的操作都是由SubList类实现的(除了自身的SubList方法外),那么,我们就直接来看SubList类的代码:
1700444254
1700444255 class SubList<E>extends AbstractList<E>{
1700444256
1700444257 //原始列表
1700444258
1700444259 private AbstractList<E>l;
1700444260
1700444261 //偏移量
1700444262
1700444263 private int offset;
1700444264
1700444265 //构造函数,注意list参数就是我们的原始列表
1700444266
1700444267 SubList(AbstractList<E>list, int fromIndex, int toIndex){
1700444268
1700444269 /*下标校验,省略*/
1700444270
1700444271 //传递原始列表
1700444272
1700444273 l=list;
1700444274
1700444275 offset=fromIndex;
1700444276
1700444277 //子列表的长度
1700444278
1700444279 size=toIndex-fromIndex;
1700444280
1700444281 }
1700444282
1700444283 //获得指定位置的元素
1700444284
1700444285 public E get(int index){
1700444286
1700444287 /*校验部分,省略*/
1700444288
1700444289 //从原始字符串中获得指定位置的元素
1700444290
1700444291 return l.get(index+offset);
1700444292
1700444293 }
1700444294
1700444295 //增加或插入
1700444296
1700444297 public void add(int index, E element){
1700444298
[ 上一页 ]  [ :1.700444249e+09 ]  [ 下一页 ]