Java Arrays and ArrayLists COMP T1 #5

Slides:



Advertisements
Similar presentations
Review Generics and the ArrayList Class
Advertisements

Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Java POWERED BY: ARVIND DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING RADHA GOVIND GROUP OF INSTITUTIONS,MEERUT.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Basic Algorithms on Arrays. Learning Objectives Arrays are useful for storing data in a linear structure We learn how to process data stored in an array.
Programming with Collections Collections in Java Using Arrays Week 9.
Programming with Collections Grouping & Looping - Collections and Iteration Week 7.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Objects Real and Java COMP.
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Arrays and ArrayLists.
CSC 142 J(part 1) 1 CSC 142 The ArrayList class [Reading: chapter 10]
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.
Roles of Variables with Examples in Python ® © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.
CompSci Arrays  Aggregate data type  Deal with items of same type  Lists of words  Numbers  Analogies  Mailboxes in post office  CD racks.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
List Interface and Linked List Mrs. Furman March 25, 2010.
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
C# E1 CSC 298 Arrays in C#. C# E2 1D arrays  A collection of objects of the same type  array of integers of size 10 int[] a = new int[10];  The size.
COMP More About Arrays Yi Hong June 05, 2015.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
Collections and Iteration Week 13.  Collections  ArrayList objects  Using loops with collections Collections and Iteration CONCEPTS COVERED THIS WEEK.
Jeopardy $100 VariablesErrorsLoops Classes and Objects Program Structure $200 $300 $400 $500 $400 $300 $200 $100 $500 $400 $300 $200 $100 $500 $400 $300.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 GEORGE KOUTSOGIANNAKIS Copyright: 2016 Illinois Institute of Technology/George Koutsogiannakis 1.
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
Review. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Objects and Classes Objects and Classes –State.
Coming up ArrayList ArrayList vs Array – Declaration – Insertion – Access – Removal Wrapper classes Iterator object.
Chapter VII: Arrays.
Basic arrays, binary search, selection sort by amelia bateman
Objects Real and Java COMP T1 3
Sets Set is an unordered list of items
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Game Extras Pepper.
COMP 121 Week 9: ArrayList.
Objects First with Java CITS1001
Array List Pepper.
Still Aggregation and Composition
CS 106A, Lecture 19 ArrayLists
CSE 143 Lecture 5 Binary search; complexity reading:
The ArrayList Class An ArrayList is a complex data structure that allows you to add or remove objects from a list and it changes size automatically. The.
Linked List Intro CSCE 121 J. Michael Moore.
CSE 373, Copyright S. Tanimoto, 2002 Performance Analysis -
Iterator.
Arrays versus ArrayList
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
CIS16 Application Development and Programming using Visual Basic.net
ArrayLists.
CSCI 3333 Data Structures Array
Lecture 5: complexity reading:
Can store many of the same kind of data together
Object Oriented Programming in java
Announcements Lab 7 due Wednesday Assignment 4 due Friday.
int [] scores = new int [10];
ArrayLists 22-Feb-19.
Collections Framework
Collections and iterators
Strings & Arrays CSCI-1302 Lakshmish Ramaswamy.
Review: libraries and packages
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Java: Variables, Input and Arrays
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
Web Design & Development Lecture 6
Linked List Intro CSCE 121.
Java String Class String is a class
Arrays, Casting & User Defined Variables
James Wei Professor Peck 9/20/2013
Collections and iterators
Arrays and ArrayLists.
SPL – PS2 C++ Memory Handling.
Presentation transcript:

Java Arrays and ArrayLists COMP 112 2017T1 #5

Array and ArrayList In Java an array Is an Object allows indexed data retrieval. Is of fixed size once built In Java an ArrayList is an indexed data structure that can change its size at runtime. Data in Arrays and ArrayLists is commonly processed by iterating over the size of the data structure. If the size of the array can be fixed when built use an array.

Array and reference arr21 z arr21 y arr22 When building an array (new int[4]) the name (z) points to a fixed size of memory. int[] z = new int[4]; z arr21 arr21 int[] y = {1,2,3,4}; y arr22 arr22 1 2 3 4

Array of fixed size constructor array size fixed at runtime

Arrays while(<cond>){<body>} return in loop ----- Meeting Notes (8/03/14 17:50) ----- ASK what == means easy syntax a[i] If (<cond>) {<body>}

Objects The API will list the methods for an Object Objects are: Of Reference type myOb == anotherAL (same object) myOb = anotherAL (point to same object) Compared by myOb.equals(anotherOb) Compare an objects “value” with .equals(_) not == Beware Strings are objects but == some times works like .equals(). Hence == must not be relied upon! See example code StringEqu.java.

ArrayList An ArrayList is an Object The elements in an ArrayList are also Objects How do you: Find out if two ArrayLists are the same? Copy one ArrayList to another? Two Arrays of Integers are the same if each index contains Integers with the same value. If a student is represented by a Student Object (each with a unique ID) then two arrays of Students are the same if they contain the same references.

Look up API from BlueJ Type ClassName. Type Ctrl space

ArrayList or Array ArrayList has indexed retrieval run time change of size you can add and delete items while iterating! Array size fixed when built easy syntax a[i] Be very careful when deleting Google stackoverflow