Chapter 16 Flashcards
Java collections framework contain other ______ generic data-structures
Prebuilt
Examples of collections
Contacts list, music playlist, members of sport teams
What do iterators do
Walk through collections
A collection is a _____ ______ (actually an object) that can hold references to other objects
Data structure
Usually collections contain references to objects of any type that has the ______ ___________ (inheritance, composition is a has-a relationship) with the collection’s element type. The collections-framework interfaces declare the operations to be performed generically on various types of collections.
Is-a relationship
Interface Collection is the ______ __________ in the collections hierarchy from which interfaces Set, Queue and List are derived.
Root interface
The collections-framework classes and interfaces are members of package ________
Java.util
As a result, the Object references obtained from a collection needed to be ________ to an appropriate type to allow the program to process the objects correctly. __________ should be avoided
Downcast
Wrapper classes
Boolean, Byte, Character, Double, Float, Integer, long and short
T/F
Wrapper classes are final classes so you can’t extend them. Primitive types do not have methods, so the methods related to a primitive type are located in the corresponding type-wrapper class
T
takes primitives (int, double, Boolean, float, etc) and turn them into reference (Double, Integer, etc) types (generic classes/containers require reference classes).
converts a primitive type to an object of the corresponding type-wrapper class (reference type). Performed automatically
Boxing
Our of reference into primitive type
Unboxing
What are proper generic classes
ArrayList, LinkedList, Iterator, Map, Set
___________ is the same as an array, but it is dynamic/mutable (resizable).
ArrayList
T/F the List interface is implemented by ArrayList and LinkedList
True
List [name] = new ArrayList<>();
T
a collection that associates keys to values and cannot contain duplicate keys. _____ does NOT derive from Collection.
Map
a collection that does not contain duplicates
Set
an ordered collection that can contain duplicate elements.
List
Methods such as sort, reverse, addAll, shuffle etc are from
Static class collections (contains bulk operations)
What does method Add() do from class List
adds elements to the end of the List
From List
appends all elements of one list to another. Example: list1.addAll(list2); sets list2 to null.
AddAll
From List
Prints list contents
printList
Iterator uses
When you want to change the contents (for loop goes through contents)