Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Collections.

Similar presentations


Presentation on theme: "Intro to Collections."— Presentation transcript:

1 Intro to Collections

2 Advantages of Array collections
Easily traversed Efficient Conceptually easy (based on “old” languages)

3 Disadvantages Static – to increase size, must make a new one and copy. (DynamicArray.java, DynamicArrayDriver.java) May have unused space and must work around that (DynamicArray2.java, DynamicArray2Driver.java)

4 Enter ArrayList A “dynamic array” in the java.util package.
Provides add, get, and remove methods Makes it easy to pull an element from the middle if we wish. ArrayList.html ArrayListDemo.java

5 Hmmmmm?? Wait a minute! Didn’t I see that ArrayList requires Objects? or at least elements of some class type? Is int an object? Whoa! What’s going on here?

6 Generics Review Collections should be made “type-safe”.
We can define a single data type or a “family” of data types (recall interfaces, inheritance).

7 Another kind of data structure
HashMap – A dynamic collection Values are “mapped” to some kind of key The key object provides the way to retrieve the underlying value object. HashMap.html

8 And yet another HashMap requires the Key to iterate over the values. We may not know the Key. Sometimes we want to iterate over the entire collection. Enter the HashSet. add, remove….what’s missing?

9 Iterator Interface which provides basic functions to traverse a collection. next() hasNext() remove() another iterator that we are familiar with.

10 Brief description of PA7
You will be required to design a solution. You will be required to choose a suitable collection. You will be required to document your choice of solution. The coding will be more extensive than PA5 (maybe not PA6) but choosing the right data structure will simplify your job. Due April 25 – No late submissions!


Download ppt "Intro to Collections."

Similar presentations


Ads by Google