Collections Methods Flashcards Preview

OCP > Collections Methods > Flashcards

Flashcards in Collections Methods Deck (31):
1

Collection boolean add(Element elem)

Adds elem into the underlying container

2

Collection void clear()

Removes all elements from the container

3

Collection boolean isEmpty()

Returns true if empty, false if not.

4

Collection Iterator iterator()

Returns an Iterator object for iterating over the container.

5

Collection int size()

Returns the number of elements in the container

6

Collection Object[] toArray()

Returns an array that has all elements in the container.

7

Collection boolean addAll(Collection extends element> coll)

Adds all the elements in coll into the underlying container

8

Collection boolean containsAll(Collection> coll)

Checks if all elements given in coll are present in the underlying container.

9

Collection boolean removeAll(Collection> coll)

Removes all elements from the underlying container that are also present in coll.

10

Collection boolean retainAll(Collection> coll)

Retains elements in the underlying container only if they are also present in coll; removes all other elements.

11

Iterator boolean hasNext()

Returns true if there are more elements to traverse.

12

Iterator E next()

Moves the iterator to the next element and returns that element.

13

Iterator void remove()

Removes the last visited element from the underlying container. next() must be called before calling remove, otherwise throws IllegalStateException.

14

ListIterator boolean hasPrevious()

Checks if the iterator has more elements to traverse in the previous direction.

15

ListIterator Element previous()

Moves the iterator to the next element and returns that next element in reverse direction()

16

ListIterator int nextIndex()

Returns the index of the next element in forward direction.

17

ListIterator int previousIndex()

Returns the index of the next element in reverse direction.

18

ListIterator void set(Element element)

Replaces the last element visited (using next or previous) with element.

19

ListIterator void add(Element element)

Adds the element to the list at the current iteration position.

20

Deque void addFirst(Element element)

Adds the element to the front of the deque. Raises Exception if full.

21

Deque void addLast(Element element)

Adds the element to the end of the deque. Raises Exception if full.

22

Deque Element removeFirst()

Removes an element from the front of the Deque and returns it. Raises NoSuchElementException if empty.

23

Deque Element removeLast()

Removes and returns the element at the end of the deque. Raises NoSuchElementException if empty.

24

Deque Element getFirst()

Returns the first element from the Deque, does not remove. Raises NoSuchElementException if empty.

25

Deque Element getLast()

Returns the last element from the Deque, does not remove. Raises NoSuchElementException if empty.

26

Deque boolean offerFirst(element)

Returns true if the element was added to the front, false if the deque is full.

27

Deque boolean offerLast(element)

Returns true if the element was added to the back, false if the deque is full.

28

Deque Element pollFirst()

Removes and returns an element from the front. Returns null if the deque is empty.

29

Deque Element pollLast()

Removes and returns an element from the back. Returns null if the deque is empty.

30

Deque Element peekFirst()

Returns but does not remove the first element. Returns null if the deque is empty.

31

Deque Element peekLast()

Returns but does not remove the last element. Returns null if the deque is empty.