Interface List<E>

Type Parameters:
E - the element type
All Superinterfaces:
Iterable<E>
All Known Implementing Classes:
ArrayList

public interface List<E> extends Iterable<E>
A simplified version of the java.util.List interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int i, E e)
    Inserts the given element at the specified index of the list, shifting all subsequent elements in the list one position further to make room.
    get(int i)
    Returns (but does not remove) the element at index i.
    boolean
    Tests whether the list is empty.
    Returns an iterator of the elements stored in the list.
    remove(int i)
    Removes and returns the element at the given index, shifting all subsequent elements in the list one position closer to the front.
    set(int i, E e)
    Replaces the element at the specified index, and returns the element previously stored.
    int
    Returns the number of elements in the list.

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • size

      int size()
      Returns the number of elements in the list.
      Returns:
      number of elements in the list
    • isEmpty

      boolean isEmpty()
      Tests whether the list is empty.
      Returns:
      true if the list is empty, false otherwise
    • get

      E get(int i) throws IndexOutOfBoundsException
      Returns (but does not remove) the element at index i.
      Parameters:
      i - the index of the element to return
      Returns:
      the element at the specified index
      Throws:
      IndexOutOfBoundsException - if the index is negative or greater than size()-1
    • set

      E set(int i, E e) throws IndexOutOfBoundsException
      Replaces the element at the specified index, and returns the element previously stored.
      Parameters:
      i - the index of the element to replace
      e - the new element to be stored
      Returns:
      the previously stored element
      Throws:
      IndexOutOfBoundsException - if the index is negative or greater than size()-1
    • add

      void add(int i, E e) throws IndexOutOfBoundsException
      Inserts the given element at the specified index of the list, shifting all subsequent elements in the list one position further to make room.
      Parameters:
      i - the index at which the new element should be stored
      e - the new element to be stored
      Throws:
      IndexOutOfBoundsException - if the index is negative or greater than size()
    • remove

      E remove(int i) throws IndexOutOfBoundsException
      Removes and returns the element at the given index, shifting all subsequent elements in the list one position closer to the front.
      Parameters:
      i - the index of the element to be removed
      Returns:
      the element that had be stored at the given index
      Throws:
      IndexOutOfBoundsException - if the index is negative or greater than size()
    • iterator

      Iterator<E> iterator()
      Returns an iterator of the elements stored in the list.
      Specified by:
      iterator in interface Iterable<E>
      Returns:
      iterator of the list's elements