同样看的都是jdk1.8 中 ArrayList中的源码,整理测试一下而已
ListIterator(int index)方法,返回指定下标(包含该下标)后的值,此时index位置的元素就是新列表迭代器的第一个值。是不是感觉有点像substring(intindex)?
注:ArrayList类同时还提供了 listIterator() 方法,此方法与listIterator(int index)的差异是index=0,
此方法可以将ArrayList转换成ListIterator.
下面是源码及测试代码

源码:

     /**
* Returns a list iterator over the elements in this list (in proper
* sequence), starting at the specified position in the list.
* The specified index indicates the first element that would be
* returned by an initial call to {@link ListIterator#next next}.
* An initial call to {@link ListIterator#previous previous} would
* return the element with the specified index minus one.
*
* <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
*
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public ListIterator<E> listIterator(int index) {
if (index < 0 || index > size)
throw new IndexOutOfBoundsException("Index: "+index);
return new ListItr(index);
}

测试代码:

 import java.util.ListIterator;

 public class listIteratorTest {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
ListIterator<String> a = list.listIterator(2);
while (a.hasNext()) {
System.out.println(a.next());
} }
} 运行结果:
c
d
e

ArrayList 进阶方法之ListIterator的更多相关文章

  1. NSIS脚本入门和进阶方法

    NSIS(Nullsoft Scriptable Install System)是一个开源的 Windows 系统下安装程序制作程序.它提供了安装.卸载.系统设置.文件解压缩等功能.对于新手来说,它有 ...

  2. 编写测试类,了解ArrayList的方法

    这篇文章主要介绍了C#中动态数组用法,实例分析了C#中ArrayList实现动态数组的技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C#中动态数组用法.分享给大家供大家参考.具体分析如下 ...

  3. 将java中数组转换为ArrayList的方法实例(包括ArrayList转数组)

    方法一:使用Arrays.asList()方法   1 2 String[] asset = {"equity", "stocks", "gold&q ...

  4. ArrayList.subList方法使用总结

    ArrayList.subList方法使用总结 示例 List<String> list=new ArrayList<>(); list.add("d"); ...

  5. LinkedList方法总结 ListIterator和Iterator的区别

    LinkedList也像ArrayList一样实现了基本的接口,但是它执行某些从操作时比ArrayList更高效,但在随机访问方面要逊色一些.LinkedList中有一些方法虽然名字不同,但可以完成相 ...

  6. 遍历Arraylist的方法:

    遍历Arraylist的几种方法: Iterator it1 = list.iterator();        while(it1.hasNext()){            System.out ...

  7. 遍历Arraylist的方法

    package com.test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; publ ...

  8. ArrayList 冷门方法

    以下代码片都是 jdk1.8 ArrayList中的官方代码 /** * Constructs a list containing the elements of the specified * co ...

  9. 集合Arraylist的方法的使用和打印

    package chapter090; import java.util.ArrayList;import java.util.List; public class TestList01 { publ ...

随机推荐

  1. Pascal's Triangle II leetcode

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  2. 利用cropper插件裁剪本地图片,然后将裁剪过后的base64图片上传至七牛云空间

    现在做的项目需要做一些图片处理,由于时间赶急,之前我便没有处理图片,直接将图片放在input[type=file]里面,以文件的形式提交给后台,这样做简直就是最低级的做法,之后各种问题便出来了,人物头 ...

  3. 本地存储和cookies之间的区别

  4. iOS 集成Weex入门教程

    前言 自Weex发布伊始, 其口号 "Write Once, Run Everywhere"就吸引了大批前端与客户端程序猿纷纷入坑, 我也不能独善其中. 就我目前所学习Weex的经 ...

  5. springmvc.xml或spring.xml 能运行配置文件总是出现错误

    1:在java开发时总遇到配置文件配置正确,可以运行但有时显示错误.例如下图 上面配置文件正确但有时显错就不能运行.原因是配置文件的约束项错了. 原因是自己的jar包和配置文件版本不同.如果电脑联网它 ...

  6. Linux+Nginx+Asp.net Core部署

    上篇<Docker基础入门及示例>文章介绍了Docker部署,以及相关.net core 的打包示例.这篇文章我将以oss.offical.site站点为例,主要介绍下在linux机器下完 ...

  7. 分离数据库时出错:无法对数据库'XXX' 执行删除,因为它正用于复制"的解决方法

    出现的原因是要分离的数据库是一个发布订阅的数据库.因为正在复制,所以无法脱机. 解决办法是停止发布订阅,或者删掉它..再分离.有部分情况是在复制目录下并没有看到发布订阅. 有可能是因为以前建立发布订阅 ...

  8. ICC_lab总结——ICC_lab4:时钟树综合

    时钟树综合的理论知识总结在这里:http://www.cnblogs.com/IClearner/p/6580034.html 下面是实践环节:使用ICC进行时钟树综合. 这个实验的目标是: ·设置C ...

  9. winow7安装django 1.9.1

    1.下载django https://www.djangoproject.com/download/ 2.解压,并到该目录下 执行 python setup.py install 3.验证是否安装成功 ...

  10. 配置uwsgi

    首先要明确的是,如果你喜欢用命令行的方式(如shell)敲命令,那可以省去任何配置. 但是,绝大多数人,还是不愿意记那么长的命令,反复敲的.所以uwsgi里,就给大家提供了多种配置,省去你启动时候,需 ...