Java Reference
In-Depth Information
31
public boolean
remove(E e);
remove(e)
32
33
/** Remove the element at the specified position in this list.
34
* Shift any subsequent elements to the left.
35
* Return the element that was removed from the list. */
36
public
E remove(
int
index);
remove(index)
37
38
/** Replace the element at the specified position in this list
39
* with the specified element and return the old element. */
40
public
Object set(
int
index, E e);
set(index, e)
41
42
/** Return the number of elements in this list */
43
public int
size();
size(e)
44 }
MyAbstractList
declares variable
size
to indicate the number of elements in the list.
The methods
isEmpty()
,
size()
,
add(E)
, and
remove(E)
can be implemented in the
class, as shown in Listing 24.2.
«interface»
java.lang.Iterable
<
E
>
+
iterator(): Iterator<E>
Returns an iterator for the elements in this collection.
«interface»
MyList
<
E
>
+
add(e: E): void
Appends a new element at the end of this list.
+
add(index: int, e: E): void
Inserts a new element at the specified index in this list.
+
clear(): void
Removes all the elements from this list.
+
contains(e: E): boolean
Returns true if this list contains the specified element.
+
get(index: int): E
Returns the element from this list at the specified index.
+
indexOf(e: E): int
Returns the index of the first matching element in this list.
+
isEmpty(): boolean
Returns true if this list does not contain any elements.
+
lastIndexOf(e: E): int
Returns the index of the last matching element in this list.
+
remove(e: E): boolean
Removes the element from this list.
+
size(): int
Returns the number of elements in this list.
+
remove(index: int): E
Removes the element at the specified index and returns the removed element.
+
set(index: int, e: E): E
Sets the element at the specified index and returns the element being replaced.
MyAbstractList
<
E
>
#size: int
The size of the list.
#MyAbstractList()
Creates a default list.
#MyAbstractList(objects: E[])
Creates a list from an array of objects.
+add(e: E): void
Implements the
add
method.
+isEmpty(): boolean
Implements the
isEmpty
method.
+size(): int
Implements the
size
method.
+remove(e: E): boolean
Implements the
remove
method.
F
IGURE
24.3
MyList
defines the methods for manipulating a list.
MyAbstractList
provides a partial implementation
of the
MyList
interface.
Search WWH ::
Custom Search