An Interesting Article Big Data's Impact in the World - - PowerPoint PPT Presentation

an interesting article
SMART_READER_LITE
LIVE PREVIEW

An Interesting Article Big Data's Impact in the World - - PowerPoint PPT Presentation

ArrayList s An Interesting Article Big Data's Impact in the World http://www.nytimes.com/2012/02/12/sunday-review/big-datas-impact-in-the-world.html?src=me&ref=general&pagewanted=all Announcements Hangman due in one week


slide-1
SLIDE 1

ArrayLists

slide-2
SLIDE 2

An Interesting Article

“Big Data's Impact in the World”

http://www.nytimes.com/2012/02/12/sunday-review/big-datas-impact-in-the-world.html?src=me&ref=general&pagewanted=all

slide-3
SLIDE 3

Announcements

  • Hangman due in one week (Wednesday,

February 22).

  • YEAH hours right after lecture today:

4:15 – 5:15PM in 370-370.

slide-4
SLIDE 4

Reading a File

try { BufferedReader br = /* … open the file … */ while (true) { String line = br.readLine(); if (line == null) break; /* … process line … */ } br.close(); } catch (IOException e) { /* … handle error … */ }

We can only remember one line

  • f the file at a

time!

slide-5
SLIDE 5

Remembering Lots of Data

  • Declare multiple variables.
  • Makes code really hard to read.
  • Have to know how much space in advance.
  • Can't treat variables uniformly.
  • Store it in the canvas.
  • Only works for GObjects.
  • Can't easily retrieve them (getElementAt requires

locations)

  • Store it as a String.
  • Impractical for non-text information.
slide-6
SLIDE 6

Looking Closer at Strings

H e l l

  • !

1 2 3 4 5

  • A string stores a sequence of multiple

characters.

  • Can access characters by index by calling

charAt.

  • Every character type is the same.
  • Namely, type char.
slide-7
SLIDE 7

Looking Closer at Strings

H e l l

  • !

1 2 3 4 5

A string stores a sequence of multiple characters.

Can access characters by index by calling charAt.

Every character type is the same.

Namely, type char.

What if we don't want to store chars?

slide-8
SLIDE 8

Introducing ArrayList

137 42 314 271 160 178

1 2 3 4 5

  • An ArrayList stores a sequence of

multiple objects.

  • Can access objects by index by calling get.
  • All stored objects have the same type.
  • You get to choose the type!
slide-9
SLIDE 9

Strings and ArrayLists

  • Both String and ArrayList store zero-

indexed sequences.

  • Strings store chars.
  • ArrayLists store objects.
  • ArrayLists, unlike Strings, are mutable.
  • You can insert, remove, and replace

elements.

slide-10
SLIDE 10

Importing ArrayList

  • To use ArrayList, you must

import java.util.*;

  • Do not do the following!

import acmx.export.java.util.*;

slide-11
SLIDE 11

Simple ArrayList Operations

  • You can append an element to an ArrayList

by calling arrayList.add(value)

  • You can get the nth element of an

ArrayList by calling arrayList.get(n)

  • You can see how many elements are in an

ArrayList by calling arrayList.size()

slide-12
SLIDE 12

Wrapper Types

  • ArrayList cannot directly store primitive

types.

  • Java provides wrapper types that

“wrap” a primitive type inside an object.

int double char boolean Integer Double Character Boolean

slide-13
SLIDE 13

Putting it all Together

slide-14
SLIDE 14