11 Arrays and Collections
and Generics
Using collection classes, iterators, and other common library components
Learning Outcomes
Declare and use List and ArrayList instances
Write an anonymous interface implementation
Resources
JavaFX ListView jenkov
The ArrayList Class tutorialspoint
TableView Tutorial IMPORTANT
Exam Topics
Use generics, including wildcards
Use a Java array and List, Set, Map and Deque collections, including convenience methods
Sort collections and arrays using Comparator and Comparable interfaces
Oracle Academy
3 Data Structures
3-1 Generics
3-2 Collections - Part 1
3-3 Collections - Part 2
3-4 Sorting and Searching
Section 3 Quiz
Textbook
16 Generic Collections
Tutorial / Practice Activity
3-1 Practice
3-2 Practice
3-3 Practice
3-4 Practice
Lesson Plan
Mindfulness
Eating review
Sleep
Gratitude
Previous week review
Functional interface implementation with concrete class
Functional interface implementation with anonymous class
Resource reinforcement and clarification
3-1 Generics
The most commonly used type parameter names are:
E - Element (used extensively by the Java Collections Framework)
K - Key
N - Number
T - Type
ArrayList
JP 3-2 Collections - Part 1
Create a collection without using generics
Create a collection using generics
Implement an ArrayList
Implement a Set
JP 3-3 Collections - Part 2
Implement a HashMap
Implement a stack by using a deque
Define a linked list
Define a queue
Implement a Comparable interface
JP 3-4: Sorting and Searching
Bubble Sort (two at a time)
Selection Sort (do comparisons to select the lowest number in unsorted sublist and swap it into the end of the sorted sublist)
Insertion (get the next number and do comparisons to see where it should be inserted into sorted sublist / beginning to end)
Merge (divide and conquer)
Searching
Activities
3-1
3-2
3-1
3-2
Production Project
Activities
Connecting a List of objects to a JavaFX TableView
Create a class with standard getters and setters
Like a Person class with a field for firstName
Create a TableView in fxml with same number of columns as fields you would like to display.
Like <TableColumn fx:id="firstNameCol" text="First Name" />
Create an ObservableList of the class type in the Controller
Like ObservableList<Person> people = FXCollections.observableArrayList();
Do setCellValueFactory on each column with the field name
Like firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
Note that the first word must match the id from fxml and the last word must match the field name
Set the items of the table to the list
Like tableView.setItems(people);
When you add to the ObservableList the new data will automatically show up in the table
Like people.add(new Person("Damien"));
Last week you wrote code to utilize the following functional interface with a class that implements the interface.
This week, write code to utilize the functional interface with an anonymous class:
interface MyInterface {
public void printIt(String text);
}
Anonymous Interface Implementation
MyInterface mi1 = new MyInterface() {
public void printIt(String text){
System.out.println(text);
}
};
mi1.printIt("Anonymous way");