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

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

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

ArrayList.rangeCheck介绍

[英]Checks if the given index is in range. If not, throws an appropriate runtime exception. This method does not check if the index is negative: It is always used immediately prior to an array access, which throws an ArrayIndexOutOfBoundsException if index is negative.
[中]检查给定索引是否在范围内。如果不是,则引发适当的运行时异常。此方法检查索引是否为负:它总是在数组访问之前立即使用,如果索引为负,则会引发ArrayIndexOutOfBoundsException。

代码示例

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

/**
 * Returns the element at the specified position in this list.
 *
 * @param  index index of the element to return
 * @return the element at the specified position in this list
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public E get(int index) {
  rangeCheck(index);
  return elementData(index);
}

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

/**
 * Returns the element at the specified position in this list.
 *
 * @param  index index of the element to return
 * @return the element at the specified position in this list
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public E get(int index) {
  rangeCheck(index);
  return elementData(index);
}

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

/**
 * Replaces the element at the specified position in this list with
 * the specified element.
 *
 * @param index index of the element to replace
 * @param element element to be stored at the specified position
 * @return the element previously at the specified position
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public E set(int index, E element) {
  rangeCheck(index);
  E oldValue = elementData(index);
  elementData[index] = element;
  return oldValue;
}

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

/**
 * Replaces the element at the specified position in this list with
 * the specified element.
 *
 * @param index index of the element to replace
 * @param element element to be stored at the specified position
 * @return the element previously at the specified position
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public E set(int index, E element) {
  rangeCheck(index);
  E oldValue = elementData(index);
  elementData[index] = element;
  return oldValue;
}

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

/**
 * Removes the element at the specified position in this list.
 * Shifts any subsequent elements to the left (subtracts one from their
 * indices).
 *
 * @param index the index of the element to be removed
 * @return the element that was removed from the list
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public E remove(int index) {
  rangeCheck(index);
  modCount++;
  E oldValue = elementData(index);
  int numMoved = size - index - 1;
  if (numMoved > 0)
    System.arraycopy(elementData, index+1, elementData, index,
             numMoved);
  elementData[--size] = null; // Let gc do its work
  return oldValue;
}

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

/**
 * Removes the element at the specified position in this list.
 * Shifts any subsequent elements to the left (subtracts one from their
 * indices).
 *
 * @param index the index of the element to be removed
 * @return the element that was removed from the list
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public E remove(int index) {
  rangeCheck(index);
  modCount++;
  E oldValue = elementData(index);
  int numMoved = size - index - 1;
  if (numMoved > 0)
    System.arraycopy(elementData, index+1, elementData, index,
             numMoved);
  elementData[--size] = null; // Let gc do its work
  return oldValue;
}

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

@JTranscSync
public E get(int index) {
  rangeCheck(index);
  return _get(index);
}

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

@JTranscSync
public E remove(int index) {
  rangeCheck(index);
  modCount++;
  E oldValue = _get(index);
  _remove(index);
  return oldValue;
}

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

@JTranscSync
public E set(int index, E element) {
  rangeCheck(index);
  E oldValue = _get(index);
  _set(index, element);
  return oldValue;
}

相关文章