Java Array Lists Day 2.

Slides:



Advertisements
Similar presentations
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Advertisements

Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Arrays and Array Lists CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
© A+ Computer Science - Which of the following statements assigns the letter S to the third row and first column of a two-dimensional.
The ArrayList Data Structure Standard Arrays at High Speed! More Safety, More Efficient, and Less Overhead!
int [] scores = new int [10];
The ArrayList Data Structure The Most Important Things to Review.
The ArrayList Data Structure Standard Arrays at High Speed!
Arrays and Array Lists CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Exposure Java 2011 APCS Edition
Sixth Lecture ArrayList Abstract Class and Interface
Lecture 20: Wrapper Classes and More Loops
CSC111 Quick Revision.
Collections.
while Repetition Structure
(like an array on steroids)
Chapter 1 Introduction to Java
Dialogues and Wrapper Classes
TK1114 Computer Programming
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Preconditions precondition: Something your method assumes is true at the start of its execution. Often documented as a comment on the method's header:
Array List Pepper.
For Monday Read WebCT quiz 18.
Interfaces.
Java Array Lists 2/2/2016.
Java Array Lists 2/13/2017.
CS 106A, Lecture 19 ArrayLists
Java Enter your code from FRQ to Shell
Polymorphism.
More Loops.
Building Java Programs
CS 200 Objects and ArrayList
Chapter 8 The Loops By: Mr. Baha Hanene.
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
int [] scores = new int [10];
Sorts on the AP Exam Insertion Sort.
ArrayLists.
CSE 143 Lecture 2 Collections and ArrayIntList
For Wednesday No new reading No quiz.
Dynamic Data Structures and Generics
For Loops.
Computer Science 2 Getting an unknown # of …. Into an array.
int [] scores = new int [10];
slides created by Ethan Apter
Arrays.
Array Lists CSE 1310 – Introduction to Computers and Programming
Java Array Lists 2/13/2017.
Lecture 13: ArrayLists AP Computer Science Principles
ArrayLists 22-Feb-19.
Arrays I Handling lists of data.
CS 200 Objects and ArrayList
Lecture 16: Arraylist Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson All rights reserved.
Dynamic Data Structures and Generics
Building Java Programs
ArrayList Day 3 Be able to read AP Mult Choice questions tied to ArrayLists Be able to write a program that uses ArrayLists that analyzes numbers.
slides created by Alyssa Harding
Creating and Modifying Text part 3
Review: libraries and packages
AP Computer Science A 2/6/2018.
Java: Variables, Input and Arrays
List Interface ArrayList class implements the List Interface
Program: Mini Phone Book 2/11/2016
Random Numbers while loop
int [] scores = new int [10];
Dry Run Fix it Write a program
CS 200 Objects and ArrayList
First Semester Review.
Collections.
Java Coding 6 David Davenport Computer Eng. Dept.,
Presentation transcript:

Java Array Lists Day 2

Goals Review the AP Java subset of ArrayList methods Create a resource in your notes for Integer class methods and constants that are part of the AP subset. Be able to read und solve Multiple Choice type questions that use ArrayLists. Be able to write a second ArrayList program

Array List: Review Creating an ArrayList A dynamic array of objects. Need to use Wrapper classes for primitives Creating an ArrayList ArrayList<SomeClass> listName = new ArrayList<SomeClass>(); ArrayList<String> list = new ArrayList<String>(); ArrayList<Integer> num = new ArrayList<Integer>(); ArrayList methods integerVariable = alist.size(); alist.add(obj); alist.add(index, obj); objAns = alist.get(index); objAns = alist.set(index, obj); alist.set(index, obj); objAns = alist.remove(N); alist.remove(N);

Warm up Use JavaDocs to look up the following for the Integer class and add these to your notes. Constructors .intValue() .compareTo() .equals() .MIN_VALUE .MAX_VALUE

What does this code do?

Note: This will display the entire arraylist!! Sample Question 2. Consider the following code segment. ArrayList <Integer> list = new ArrayList<Integer> (); list.add(new Integer(1)); list.add(new Integer(2)); list.add(new Integer(3)); list.set(2, new Integer(4)); list.add(2, new Integer(5)); list.add(new Integer(6)); System.out.println(list); What is printed as a result of executing the code segment? (A) [1, 2, 3, 4, 5] (B) [1, 2, 4, 5, 6] (C) [1, 2, 5, 4, 6] (D) [1, 5, 2, 4, 6] (E) [1, 5, 4, 3, 6] Note: This will display the entire arraylist!!

3. Consider the following data field and method. private ArrayList nums; // precondition: nums.size() > 0; // nums contains Integer objects public void numQuest() { int k = 0; Integer zero = new Integer(0); while (k< nums.size()) if (nums.get(k).equals(zero)) nums.remove(k); k++; } Assume that ArrayList nums initially contains the following Integer values. [0, 0, 4, 2, 5, 0, 3, 0] What will ArrayList nums contain as a result of executing numQuest ? (A) [0, 0, 4, 2, 5, 0, 3, 0] (B) [4, 2, 5, 3] (C) [0, 0, 0, 0, 4, 2, 5, 3] (D) [3, 5, 2, 4, 0, 0, 0, 0] (E) [0, 4, 2, 5, 3]

ArrayList Program #2 Just Above Average Random Compliment Generator Input 10 integers. Output: The total, average and number of scores above the average of these scores. Push: Create a Person class with name and score and show the names of above average people. Random Compliment Generator Initialize: Code 5 compliments stored in an arrayList Process: Ask the user if they would like a compliment. They can ask for compliments as long as they would like. (Semantics of a while loop) Output: The computer will randomly pick and show a compliment. Phone(y) Book Input: An unknown number of names Process: Add the names to the list so the list remains in order. Output: Show all the names Push: Create a Contact class that includes phone, name, and email and use an arrayList of Contacts.