Interface ListOfString_Interface

All Known Implementing Classes:
SLinked_ListOfString

public interface ListOfString_Interface
A singly-linked list of Strings.
Author:
kevin
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int i, String str)
    Adds the given element at the given index position i.
    void
    add(String str)
    Adds the given element to the end of this list.
    void
    Adds the given element to the beginning of this list.
    void
    Adds the given element to the end of this list.
    void
    Removes all list elements, if any exist.
    boolean
    Returns true if the specified element in in this list, returns false otherwise.
    int
    Returns the index of the first occurrence of the specified element, -1 if the element is not in this list
    get(int i)
    Returns the element at the given index position.
    Returns the first element in this list.
    Returns the last element in this list.
    boolean
    Returns true if this list is empty, returns false otherwise.
    int
    Returns the index of the last occurrence of the specified element, -1 if the element is not in this list not found.
    remove(int i)
    Removes and returns the element at the specified index position in the list.
    Removes and returns the first occurrence of the specified element.Returns null if the element is not in this list.
    Removes and returns the first element in this list.
    Removes and returns the last element in this list.
    set(int i, String str)
    Replaces the element at the given index position with the given element and returns the old element.
    Replaces the first element with the given element and returns the old element.
    Replaces the last element with the given element and returns the old element.
    int
    Returns the number of elements in this list.
    Returns a string containing each element in this list, separated by commas, enclosed in square brackets.
  • Method Details

    • add

      void add(int i, String str) throws IndexOutOfBoundsException
      Adds the given element at the given index position i.
      Parameters:
      i - index position where the given element will be added
      str - element to be added at the given index position
      Throws:
      IndexOutOfBoundsException - if i < 0 or i > size() Note: that it is OK for i to equal size()
    • addFirst

      void addFirst(String str)
      Adds the given element to the beginning of this list.
      Parameters:
      str - element to be added to the beginning of this list
    • addLast

      void addLast(String str)
      Adds the given element to the end of this list.
      Parameters:
      str - element to be added to the end of this list
    • add

      void add(String str)
      Adds the given element to the end of this list.
      Parameters:
      str - element to be added to the end of this list
    • remove

      String remove(int i) throws IndexOutOfBoundsException
      Removes and returns the element at the specified index position in the list.
      Parameters:
      i - index of element to be removed and returned
      Returns:
      element stored at the given index position
      Throws:
      IndexOutOfBoundsException - if i < 0 or i ≥ size()
    • removeFirst

      String removeFirst() throws IllegalStateException
      Removes and returns the first element in this list.
      Returns:
      first element in this list
      Throws:
      IllegalStateException - if this list is empty.
    • removeLast

      String removeLast() throws IllegalStateException
      Removes and returns the last element in this list.
      Returns:
      last element in this list
      Throws:
      IllegalStateException - if this list is empty.
    • remove

      String remove(String str)
      Removes and returns the first occurrence of the specified element.Returns null if the element is not in this list.
      Parameters:
      str - element to be removed from this list
      Returns:
      the element that was removed
    • get

      String get(int i) throws IndexOutOfBoundsException
      Returns the element at the given index position.
      Parameters:
      i - index of the list element to return
      Returns:
      the element located at the given index position
      Throws:
      IndexOutOfBoundsException - if i < 0 or i ≥ size()
    • getFirst

      String getFirst() throws IllegalStateException
      Returns the first element in this list.
      Returns:
      the first element in this list.
      Throws:
      IllegalStateException - if list is empty.
    • getLast

      String getLast() throws IllegalStateException
      Returns the last element in this list.
      Returns:
      the last element in this list
      Throws:
      IllegalStateException - if this list is empty.
    • set

      String set(int i, String str) throws IndexOutOfBoundsException
      Replaces the element at the given index position with the given element and returns the old element.
      Parameters:
      i - index of the element to be replaced
      str - new element that will be stored at the given index position
      Returns:
      element that was previously stored at the given index position
      Throws:
      IndexOutOfBoundsException - if i < 0 or i ≥ size()
    • setFirst

      String setFirst(String str) throws IllegalStateException
      Replaces the first element with the given element and returns the old element.
      Parameters:
      str - new element that will be stored as the first list element
      Returns:
      element that was previously stored as the first list element
      Throws:
      IllegalStateException - if list is empty.
    • setLast

      String setLast(String str) throws IllegalStateException
      Replaces the last element with the given element and returns the old element.
      Parameters:
      str - new element that will be stored as the last list element
      Returns:
      element that was previously stored as the last list element
      Throws:
      IllegalStateException - if list is empty.
    • isEmpty

      boolean isEmpty()
      Returns true if this list is empty, returns false otherwise.
      Returns:
      true if this list is empty, returns false otherwise
    • contains

      boolean contains(String str)
      Returns true if the specified element in in this list, returns false otherwise.
      Parameters:
      str - element that is being searched for
      Returns:
      true if the specified element is in this list, returns false otherwise
    • firstIndexOf

      int firstIndexOf(String str)
      Returns the index of the first occurrence of the specified element, -1 if the element is not in this list
      Parameters:
      str - element being searched for
      Returns:
      index of the first occurrence of the specified element, returns -1 if the element is not in this list
    • lastIndexOf

      int lastIndexOf(String str)
      Returns the index of the last occurrence of the specified element, -1 if the element is not in this list not found.
      Parameters:
      str - element being searched for
      Returns:
      index of the last occurrence of the specified element, returns -1 if the element is not in this list
    • size

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

      void clear()
      Removes all list elements, if any exist.
    • toString

      String toString()
      Returns a string containing each element in this list, separated by commas, enclosed in square brackets. For example, if a list contained the three elements "A", "B", and "C", then this method would return the String "[A, B, C"].
      Overrides:
      toString in class Object
      Returns:
      a string representation of this list.