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 TypeMethodDescriptionvoidAdds the given element at the given index position i.voidAdds the given element to the end of this list.voidAdds the given element to the beginning of this list.voidAdds the given element to the end of this list.voidclear()Removes all list elements, if any exist.booleanReturns true if the specified element in in this list, returns false otherwise.intfirstIndexOf(String str) Returns the index of the first occurrence of the specified element, -1 if the element is not in this listget(int i) Returns the element at the given index position.getFirst()Returns the first element in this list.getLast()Returns the last element in this list.booleanisEmpty()Returns true if this list is empty, returns false otherwise.intlastIndexOf(String str) 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.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.intsize()Returns the number of elements in this list.toString()Returns a string containing each element in this list, separated by commas, enclosed in square brackets.
-
Method Details
-
add
Adds the given element at the given index position i.- Parameters:
i- index position where the given element will be addedstr- 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
Adds the given element to the beginning of this list.- Parameters:
str- element to be added to the beginning of this list
-
addLast
Adds the given element to the end of this list.- Parameters:
str- element to be added to the end of this list
-
add
Adds the given element to the end of this list.- Parameters:
str- element to be added to the end of this list
-
remove
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
Removes and returns the first element in this list.- Returns:
- first element in this list
- Throws:
IllegalStateException- if this list is empty.
-
removeLast
Removes and returns the last element in this list.- Returns:
- last element in this list
- Throws:
IllegalStateException- if this list is empty.
-
remove
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
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
Returns the first element in this list.- Returns:
- the first element in this list.
- Throws:
IllegalStateException- if list is empty.
-
getLast
Returns the last element in this list.- Returns:
- the last element in this list
- Throws:
IllegalStateException- if this list is empty.
-
set
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 replacedstr- 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
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
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
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
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
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"].
-