将元素添加到List集合的第一位
2016-10-28 00:00
190 查看
摘要: 将元素添加到List集合的第一位
看一下add方法的注释
翻译(有不对的地方及时指正)
总结:对API不熟
list.add(1, object)
看一下add方法的注释
/** * Inserts the specified element at the specified position in this list * (optional operation). Shifts the element currently at that position * (if any) and any subsequent elements to the right (adds one to their * indices). * * @param index index at which the specified element is to be inserted * @param element element to be inserted * @throws UnsupportedOperationException if the <tt>add</tt> operation * is not supported by this list * @throws ClassCastException if the class of the specified element * prevents it from being added to this list * @throws NullPointerException if the specified element is null and * this list does not permit null elements * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this list * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index > size()</tt>) */ void add(int index, E element);
翻译(有不对的地方及时指正)
/** * 在List中指定的位置上插入指定的元素 * (可选操作)。 将当前处于该位置的元素 * (如果有的话) 和任何后续的元素向右移 (增加他们的下标)。 * * @param index 指定被插入元素的下标 * @param element 要插入的元素 * @throws UnsupportedOperationException 如果此List不支持添加操作 * @throws ClassCastException 如果指定元素的类阻止它被添加到这个List中 * @throws NullPointerException 如果指定元素为null并且该List不允许null元素 * @throws IllegalArgumentException 如果指定元素的某些属性防止它被添加到这个List中 * @throws IndexOutOfBoundsException 如果下标超出范围(下标 < 0 || 下标 > size()) */ void add(int index, E element);
总结:对API不熟
相关文章推荐
- 将list集合的元素按照添加顺序的倒序进行排列取出
- list集合添加元素,删除元素
- c#中List <int[]>集合添加和查找元素
- 集合框架(一)续 向集合中添加一个集合、数组和List之间的相互转换、从集合中删除另一个集合所包含的元素
- List集合,泛型,将元素全部添加到集合中
- 数据数去重和将list集合中的元素添加到数组中
- c#中List <int[]>集合添加和查找元素
- 在list集合中的添加、修改、删除和遍历元素
- c#中List <int[]>集合添加和查找元素
- Java中如何循环删除一个集合(如List)中的多个元素
- 利用Stack倒序List,利用Set使List不能添加重复元素
- List 中添加多个List集合以及add() 与addAll()的区别
- 合并两个List集合。有相同的元素只存在一次
- 继承List<T>类,并且完成List的Add()(在集合的末尾添加)方法和Get()(通过索引的方式获取)方法。并且写出方法的时间复杂度。
- 在list集合中对元素进行分组
- 黑马程序员 List集合把同内容的元素删掉
- List 集合元素
- Java中如何循环删除一个集合(如List)中的多个元素
- 去除List<Object>集合中重复的元素
- 高效出去List集合和数组中的重复元素