Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
14 Cards in this Set
- Front
- Back
What is a Collection? |
an object that groups multiple elements into a single unit |
|
What are Collections used for? |
used to store, retrieve, manipulate and communicate aggregate data. typically, they represent data items that form a natural group (such as a collection of cards).or a telephone directory ( a mapping of names to phone numbers) |
|
What is the Collections Framework? |
a unified architecture for representing and manipulating collections. All collections frameworks contain the following: - Interfaces - Implementations (concrete classes) - Algorithms |
|
Collections - Interfaces |
Abstract data types that represent collections -allow collections to be manipulated independently of the details of their representation - method bodies with no implementation |
|
Collections - Implementations |
concrete implementations of the collection interfaces - reusable data structures - include ArrayList, LinkedList, HashSet, Treeset, PriorityQueue, Hashtable, HashMap, TreeMap |
|
Collections - Algorithms |
methods that perform useful computations such as SEARCHING and SORTING on objects that implement collection interfaces. the algorithms are said to be polymorphic, same method can be used on many different implementations - reusable functionality |
|
Benefits of the Java Collections Framework |
Reduces programming effort - by providing useful data structures and algorithms Increases program speed and quality - provides high performance implementations of data structures and algorithms, interchangeable Allows interoperability among unrelated APIs - the vernacular by which APIs pass collections back and forth Reduces effort to learn and to use new APIs - consistency Reduces effort to design new APIs - don't have to reinvent the wheel- they can use standard collection interfaces Fosters software reuse |
|
|
Collection - is an interface- cannot instantiate it the least common denominator that all collections implement and is used to pass collections around need to choose the right collection for the right job |
|
Conversion constructor |
all collection implementations have a constructor that takes a collection argument it allows you to convert the collection's type. You can convert from one collection type to another |
|
List |
Ordered collection can contain duplicates user has control over where in the list each element is inserted can access elements by their integer index ArrayList- usually the better-performing LinkedList- offers better performance in some circumstances |
|
List cont'd |
Allows positional access- manipulates elements based on their numerical position Search- searches for a specified object Iteration - extends iterator semantics Range view- sublist method performs arbitrary range operations on the list. |
|
Parameter argument defined as a collection allows for any collection type to be passed |
public static void showAll(Collection collection){ for (String s : collection){ System.out.println(s); } } |
|
LinkedList v ArrayList |
LinkedList implements it with a doubly- linked list. harder to add to the list- have to go through the links Easier to add more elements Easier to put elements in the middle ArrayList implements it with a dynamically resizing array. -direct access, speed is good, access an element without interfering with thee others Inserting into an arraylist is inefficient Insertions- linkedlist random access- arraylist |
|
List Ordered collection Allows duplicates Precise control over where an element is inserted Can access elements by their integer index |
ArrayList + Random Access + Direct Access- speed is good + Don't need to interfere with other elements - reallocation of memory if you run out of space - inserting is inefficient LinkedList + Insertions + easier to add more elements + easier to put elements in the middle - harder to access an element in the list as you need to go through the links |