Java Reference
In-Depth Information
contains(anEntry)
+contains(anEntry: T): boolean
Task: Sees whether the list
contains anEntry .
Input: anEntry is an object.
Output: Returns true if anEntry is in
the list, or false if not.
getLength()
+getLength(): integer
Task: Gets the number of entries
currently in the list.
Input: None.
Output: Returns the number of
entries currently in the list.
isEmpty()
+isEmpty(): boolean
Task: Sees whether the list is empty.
Input: None.
Output: Returns true if the list is
empty, or false if not.
toArray()
+toArray: T[]
Task: Retrieves all entries that are in
the list in the order in which
they occur.
Input: None.
Output: Returns a new array of the
entries currently in the list.
We have only begun to specify the behaviors of these list operations, as the specifications just
given leave some details to the imagination. Some examples will help us to better understand these
operations so that we can improve the specifications. We'll need precise specifications before we
implement the operations.
12.3
Example. When you first declare a new list, it is empty and its length is zero. If you add three
objects— a , b , and c —one at a time and in the order given, to the end of the list, the list will appear as
a
b
c
The object a is first, at position 1, b is at position 2, and c is last at position 3. 1 To save space here,
we will sometimes write a list's contents on one line. For example, we might write
a b c
to represent this list.
The following pseudocode represents the previous three additions to the specific list myList :
myList.add(a)
myList.add(b)
myList.add(c)
1.
Some people number the entries in a list beginning with 0 instead of 1.
 
Search WWH ::




Custom Search