Package com.collection.arraylist
Interface CustomList<T>
- Type Parameters:
T- the type of elements stored in the list
- All Known Implementing Classes:
CustomArrayList
public interface CustomList<T>
This interface represents a custom list data structure that can store elements of type T.
It provides methods to add, remove, access, and manipulate elements within the list.
This interface is implemented by the CustomArrayClass.
-
Method Summary
Modifier and TypeMethodDescriptionvoidInserts the specified element at the specified index in the list.booleanAdds the specified element to the end of the list.booleanAdds all the elements in the specified array to the end of the list.voidclear()Removes all elements from the list, leaving it empty.booleanChecks if the list contains the specified element.get(int index) Returns the element at the specified index in the list.intReturns the index of the first occurrence of the specified element in the list.remove(int index) Removes the element at the specified index in the list.booleanRemoves the first occurrence of the specified element from the list.Replaces the element at the specified index with the specified element.intsize()Returns the number of elements in the list.
-
Method Details
-
size
int size()Returns the number of elements in the list.- Returns:
- the number of elements in the list
-
get
Returns the element at the specified index in the list.- Parameters:
index- the index of the element to retrieve- Returns:
- the element at the specified index
-
add
Adds the specified element to the end of the list.- Parameters:
element- the element to be added to the list- Returns:
- true if the element was successfully added, false otherwise
-
add
Inserts the specified element at the specified index in the list.- Parameters:
index- the index at which to insert the elementelement- the element to be inserted
-
addAll
Adds all the elements in the specified array to the end of the list.- Parameters:
elements- the array of elements to be added to the list- Returns:
- true if all elements were successfully added, false otherwise
-
remove
Removes the element at the specified index in the list.- Parameters:
index- the index of the element to be removed- Returns:
- the removed element
-
remove
Removes the first occurrence of the specified element from the list.- Parameters:
element- the element to be removed- Returns:
- true if the element was successfully removed, false otherwise
-
contains
Checks if the list contains the specified element.- Parameters:
element- the element to check for in the list- Returns:
- true if the element is found in the list, false otherwise
-
set
Replaces the element at the specified index with the specified element.- Parameters:
index- the index of the element to replaceelement- the new element to set at the specified index- Returns:
- the element previously at the specified index
-
indexOf
Returns the index of the first occurrence of the specified element in the list.- Parameters:
element- the element to search for in the list- Returns:
- the index of the element, or -1 if the element is not found
-
clear
void clear()Removes all elements from the list, leaving it empty.
-