Site Search:

Challenge 1 -- Read the Menu (Page 2)


public interface Iterable<T>
  • default void forEach(Consumer<super ? E> action)
  • Iterator<T> iterator()
  • default<T> Spliterator spliterator()
public interface Collection<E> extends Iterable<E>
Additional method signatures not in Iterable
  • boolean add(E e)
  • boolean addAll(Collection<? extends E> c)
  • void clear()
  • boolean contains(Object o)
  • boolean containsAll(Collection<?> c)
  • boolean equals(Object o)
  • int hashCode()
  • boolean isEmpty()
  • default Stream parallelStream()
  • boolean remove(Object o)
  • boolean removeAll(Collection<?> c)
  • default boolean removeIf(Predicate<? super E> filter)
  • boolean retainAll(Collection<?> c)
  • int size()
  • default Stream<E> stream()
  • Object[] toArray()
  • <T> Object[] toArray(T[] a)

public interface Set<E> extends Collection<E>
Set's methods have exactly the same signatures as those of Collection, however, the intended methods implementation is different. Set methods' javadoc is more specific for a collection that can not have duplicate elements.

public interface List<E> extends Collection<E>
Additional methods signature not in Collection
  • void add(int index, E element)
  • boolean addAll(int index, Collection<? extends E> c)
  • E get(int index)
  • int indexOf(Object o)
  • int lastIndexOf(object o)
  • ListIterator<E> listIterator()
  • ListIterator<E> listIterator(int index)
  • E remove(int index)
  • default void replaceAll(UnaryOperator<E> operator)
  • E set(int index, E element)
  • default void sort(Comparator<? super E> c)
  • List<E> subList(int fromIndex, int toIndex)

public interface Queue<E> extends Collection<E>
Queue defined extra methods to handle head of the queue. 
Summary of Queue methods
Throws exception Returns special value
Insert add(e) offer(e)
Remove remove() poll()
Examine element() peek()
  • boolean add(E e)
  • E element()
  • boolean offer(E e)
  • E remove()
  • E peek()
  • E poll()

public interface Deque<E> extends Queue<E>
Deque allow handling elements from either head or tail
Summary of Deque methods
First Element (Head) Last Element (Tail)
Throws exception Special value Throws exception Special value
Insert addFirst(e) offerFirst(e) addLast(e) offerLast(e)
Remove removeFirst() pollFirst() removeLast() pollLast()
Examine getFirst() peekFirst() getLast() peekLast()

Comparison of Queue and Deque methods
Queue Method Equivalent Deque Method
add(e) addLast(e)
offer(e) offerLast(e)
remove() removeFirst()
poll() pollFirst()
element() getFirst()
peek() peekFirst()

public interface BlockingQueue<E> extends Queue<E>
When the queue is empty or full, BlockingQueue have extra methods to wait for a while or block. 
Summary of BlockingQueue methods
Throws exception Special value Blocks Times out
Insert add(e) offer(e) put(e) offer(e, time, unit)
Remove remove() poll() take() poll(time, unit)
Examine element() peek() not applicable not applicable
A BlockingQueue is thread safe, doesn't allow null values, and may not may not be capacity constrained.

public interface BlockingDeque<E> extends BlockingQueue<E>
BlockingDeque expands BlockingQueue to allow handle head and tail. 
Summary of BlockingDeque methods
First Element (Head)
Throws exception Special value Blocks Times out
Insert addFirst(e) offerFirst(e) putFirst(e) offerFirst(e, time, unit)
Remove removeFirst() pollFirst() takeFirst() pollFirst(time, unit)
Examine getFirst() peekFirst() not applicable not applicable
Last Element (Tail)
Throws exception Special value Blocks Times out
Insert addLast(e) offerLast(e) putLast(e) offerLast(e, time, unit)
Remove removeLast() pollLast() takeLast() pollLast(time, unit)
Examine getLast() peekLast() not applicable not applicable
BlockingDeque is thread safe, doesn't allow null and may or may not be capacity constrained.

public interface TransferQueue<E> extends BlockingQueue<E>
A blockingQueue in which a producer may wait for the consumers to receive the elements. 
  • int getWaitingConsumerCount()
  • boolean hasWaitingConsumer()
  • void transfer(E e)
  • boolean tryTransfer(E e)
  • boolean tryTransfer(E e, long timeout, TimeUnit unit)

Collection interfaces

click images to review the interface method signatures
When you are ready, click NEXT ->

Iterable



Collection






Set



List






Queue



Deque






BlockingQueue



BlockingDeque






TransferQueue