This document provides brief specifications for common Java interfaces used for collections and iterators, including Iterator, Iterable, Comparable, Comparator, Collection, List, Set, Queue, Stack, and Map. It outlines some of their key methods like hasNext(), next(), compareTo(), get(), put(), and remove(). Implementations for List include ArrayList, for Set include HashSet, and for Queue include ArrayQueue and LinkedList.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
36 views2 pages
Documentation
This document provides brief specifications for common Java interfaces used for collections and iterators, including Iterator, Iterable, Comparable, Comparator, Collection, List, Set, Queue, Stack, and Map. It outlines some of their key methods like hasNext(), next(), compareTo(), get(), put(), and remove(). Implementations for List include ArrayList, for Set include HashSet, and for Queue include ArrayQueue and LinkedList.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Appendix (may be removed)
Brief (and simplified) specifications of some relevant interfaces and classes.
public interface Iterator <E> public boolean hasNext(); public E next (); public void remove();
public interface Iterable <E> // Can use in the ”for each” loop public Iterator <E> iterator ();
public interface Comparable<E> // Can compare this to another E
public int compareTo(E o);
public interface Comparator<E> // Can use this to compare two E’s
public int compare(E o1, E o2); public interface Collection<E> public boolean isEmpty(); public int size (); public boolean add(); public Iterator <E> iterator ();
public interface List <E> extends Collection<E>
// Implementations: ArrayList public E get( int index); public void set( int index, E element); public void add(E element); public void add(int index, E element); public void remove(int index); public void remove(Object element);
public interface Set extends Collection<E>
// Implementations: ArraySet, SortedArraySet, HashSet public boolean contains(Object element); public boolean add(E element); public boolean remove(Object element);
public interface Queue<E> extends Collection<E>
// Implementations: ArrayQueue, LinkedList public E peek (); // returns null if queue is empty public E poll (); // returns null if queue is empty public boolean offer (E element);
public class Stack<E> implements Collection<E>
public E peek (); // returns null if stack is empty public E pop (); // returns null if stack is empty public E push (E element);
public interface Map<K, V>
// Implementations: HashMap, TreeMap, ArrayMap public V get(K key); // returns null if no such key public void put(K key, V value); public void remove(K key); public Set<Map.Entry<K, V>> entrySet();