From charlesreid1

Revision as of 21:17, 9 September 2016 by Admin (talk | contribs) (→‎Materials)

Chapter 10: ArrayLists

Sections:

10.1 ArrayLists

10.2 Comparable interface

10.3 Case study: Vocabulary comparison

Section 10.1: ArrayLists

Definitions

Definitions:

  • Generic class
  • Wrapper class
  • Boxing
  • Unboxing

Materials

Introduce ArrayList object the way you would introduce the Python list

  • List: basic data type, very important
  • Difference between list and array - memory allocation and element insertion
  • Dynamic arrays

Array notation

  • Wrapper class, everything is an object, treat primitive types as objects

What kind of things would you want to do with an ArrayList?

Basic basic operations:

  • Get size

Other basic operations:

  • Get item at index i
  • Set item at index i
  • Add item, add item at index i
  • Remove item
  • Modify item at index i

Now that we have defined these basic operations, we can move on to examples/algorithms/implementations.

Section 10.2: Comparable interface

Definitions

Definitions:

  • Comparison function
  • Natural ordering

Materials

Controversy over boxing and unboxing: ArrayList<Integer> vs ArrayList<int>

Sorting ArrayList

Natural ordering and compareTo

Comparing strings

Implementing the comparable interface

Utilizing comparable with sort

Section 10.3: Vocabulary comparison

Material

Some efficiency considerations

Version 1: compute vocabulary

  • Add unique words to ArrayList, and sort

Version 2: compute overlap

  • Number of matches between two sentences

Version 3: complete program

  • so far, build vocab list for 2 files, compute overlap between them
  • now, to deal with large files, print statistics (Nwords, Noverlapwords, Percent overlap)

Chapter 10 Summary

Deliverables

ArrayList

  • Notation, how to use it
  • Conceptualizing problems that can be easily resolved with ArrayList
  • Adding/removing and looping over ArrayLists
  • Wrapper classes

Comparable

  • Natural ordering and compareTo() function
  • Implementing the Comparable interface

Case study: Vocab comparison

  • Count number of unique words
  • Count overlap between two lists
  • Compute statistics

Chapter 10 Goodies

Profiles

(?)

Puzzle 2

Flags