java.util.ArrayList.rangeCheckForAdd()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(359)

本文整理了Java中java.util.ArrayList.rangeCheckForAdd()方法的一些代码示例,展示了ArrayList.rangeCheckForAdd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayList.rangeCheckForAdd()方法的具体详情如下:
包路径:java.util.ArrayList
类名称:ArrayList
方法名:rangeCheckForAdd

ArrayList.rangeCheckForAdd介绍

[英]A version of rangeCheck used by add and addAll.
[中]add和addAll使用的rangeCheck版本。

代码示例

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Inserts the specified element at the specified position in this
 * list. 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 IndexOutOfBoundsException {@inheritDoc}
 */
public void add(int index, E element) {
  rangeCheckForAdd(index);
  ensureCapacityInternal(size + 1);  // Increments modCount!!
  System.arraycopy(elementData, index, elementData, index + 1,
           size - index);
  elementData[index] = element;
  size++;
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Inserts the specified element at the specified position in this
 * list. 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 IndexOutOfBoundsException {@inheritDoc}
 */
public void add(int index, E element) {
  rangeCheckForAdd(index);
  ensureCapacityInternal(size + 1);  // Increments modCount!!
  System.arraycopy(elementData, index, elementData, index + 1,
           size - index);
  elementData[index] = element;
  size++;
}

代码示例来源:origin: com.jtransc/jtransc-rt

@JTranscAsync
public boolean addAll(int index, Collection<? extends E> c) {
  rangeCheckForAdd(index);
  _insert(index, c.toArray());
  if (c.size() != 0) modCount++;
  return c.size() != 0;
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Inserts all of the elements in the specified collection into this
 * list, starting at the specified position.  Shifts the element
 * currently at that position (if any) and any subsequent elements to
 * the right (increases their indices).  The new elements will appear
 * in the list in the order that they are returned by the
 * specified collection's iterator.
 *
 * @param index index at which to insert the first element from the
 *              specified collection
 * @param c collection containing elements to be added to this list
 * @return <tt>true</tt> if this list changed as a result of the call
 * @throws IndexOutOfBoundsException {@inheritDoc}
 * @throws NullPointerException if the specified collection is null
 */
public boolean addAll(int index, Collection<? extends E> c) {
  rangeCheckForAdd(index);
  Object[] a = c.toArray();
  int numNew = a.length;
  ensureCapacityInternal(size + numNew);  // Increments modCount
  int numMoved = size - index;
  if (numMoved > 0)
    System.arraycopy(elementData, index, elementData, index + numNew,
             numMoved);
  System.arraycopy(a, 0, elementData, index, numNew);
  size += numNew;
  return numNew != 0;
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Inserts all of the elements in the specified collection into this
 * list, starting at the specified position.  Shifts the element
 * currently at that position (if any) and any subsequent elements to
 * the right (increases their indices).  The new elements will appear
 * in the list in the order that they are returned by the
 * specified collection's iterator.
 *
 * @param index index at which to insert the first element from the
 *              specified collection
 * @param c collection containing elements to be added to this list
 * @return <tt>true</tt> if this list changed as a result of the call
 * @throws IndexOutOfBoundsException {@inheritDoc}
 * @throws NullPointerException if the specified collection is null
 */
public boolean addAll(int index, Collection<? extends E> c) {
  rangeCheckForAdd(index);
  Object[] a = c.toArray();
  int numNew = a.length;
  ensureCapacityInternal(size + numNew);  // Increments modCount
  int numMoved = size - index;
  if (numMoved > 0)
    System.arraycopy(elementData, index, elementData, index + numNew,
             numMoved);
  System.arraycopy(a, 0, elementData, index, numNew);
  size += numNew;
  return numNew != 0;
}

代码示例来源:origin: com.jtransc/jtransc-rt

@JTranscSync
public void add(int index, E element) {
  rangeCheckForAdd(index);
  _insert(index, element);
}

相关文章

微信公众号

最新文章

更多