generics

generics - Generics IRS W-9 Form Collection Classes Many...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Generics IRS W-9 Form Collection Classes Many predefined classes in Java are generic. Generics make these classes useful in more situations. The Java package java.util is filled with generic, “utility” classes — classes that are used to solve a wide variety of problems types. Many of these classes are container or collection classes — classes the hold many individual sub-pieces (like arrays do). These classes are organized in a rich system known as the collection classes. Collections classes share two important characteristics: 1. the individual items have arbitrary type 2. it is common to iterate over all the individual items of the collection List What is a list? A list is an ordered collection of elements, like a chain. There is a first element, a second element, and so on. There is a last element as well. Sometimes this structure is called a sequence. The same value may occur more than once (unlike a set). List Implementing our own lists: list/IntList.java list/GenericList.java List Interface in the Collection Classes interface java.util.List<E> implements Collection <E> E get (int index) E set (int index, E element) returns previous ele void add (int index, E element) E remove (int index) int size() number of elements in the list void clear() removes all the elements boolean contains (Object o) search int indexOf (Object o) index of the first occurrenc Iterator<E> iterator () List Interface in the Collection Classes The Java API has two implementations of the list interface with different performance characteristics. (In general, i.e., not specifically in the Java API, a list means a sequence of elements, often most easily accessible from the front of the collection, i.e., index==0 .) ArrayList in the Collection Classes java.util.ArrayList<E> implements List<E> ArrayList() ArrayList (int initialCapacity) void ensureCapacity (int minCapacity) void trimToSize () LinkedList in the Collection Classes java.util.LinkedList<E> implements List<E>, Dequeue<E> LinkedList() E getFirst () same as element() E getLast () void addFirst () same as push() void addLast () E removeFirst () same as pop(), remove() E removeLast () Lists If you have to save space, then use a linked list, If you have to have fast access (set/get) to random elements, then use a list implemented as an array....
View Full Document

This note was uploaded on 02/10/2012 for the course CSE 1002 taught by Professor Marico during the Spring '08 term at FIT.

Page1 / 39

generics - Generics IRS W-9 Form Collection Classes Many...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online