Chapter 8: Part 3 Collections and Two-dimensional arrays.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Introduction to C Programming
Arrays.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
Arrays. INTRODUCTION TO ARRAYS Just as with loops and conditions, arrays are a common programming construct and an important concept Arrays can be found.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Programming with Collections Collections in Java Using Arrays Week 9.
Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 *Arrays with more than one dimension *Java Collections API.
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Chapter 9 Introduction to Arrays
© The McGraw-Hill Companies, 2006 Chapter 16 Two-dimensional arrays.
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
11 Chapter 8 ARRAYS Continued. 22 MULTI-DIMENSIONAL ARRAYS A one-dimensional array is useful for storing/processing a list of values. For example: –The.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Chapter 9: Advanced Array Concepts
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays in Classes and Methods l Programming.
A First Book of ANSI C Fourth Edition
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Chapter 8 Arrays and Strings
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays in Classes and Methods l Programming.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
IT259 Foundation of Programming Using Java Unit 9 Seminar : (Chapter 8 ) Instructor : Vladimir Gubanov, PhD
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Two Dimensional Arrays Found in chapter 8, Section 8.9.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Chapter 8 Slides from GaddisText Arrays of more than 1 dimension.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Objectives You should be able to describe: One-Dimensional Arrays
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Two-Dimensional Arrays
Chapter 7 Part 2 Edited by JJ Shepherd
Presentation transcript:

Chapter 8: Part 3 Collections and Two-dimensional arrays

2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The Collections Framework: ArrayLists Two-Dimensional Arrays Common Programming Errors

3

4 The Collections Framework: ArrayLists Array –Data structure of choice for fixed-length collections of data that are related Many programming applications require variable- length lists –Java provides a set of classes referred to as the collections framework –Provides seven different types of generic data structures

5

6 The Collections Framework The Collections class: –Supports container classes –Provides functions for: Searching Sorting Random shuffling Reverse-ordering

7

8

9

10 The Iterator Class Similar to an array’s index Generalized index that keeps track of object’s position within a container For some classes it provides the primary means of accessing individual elements Obtaining an iterator: –Iterator iter = x.iterator();

11 Parallel Arrays as Records Parallel arrays: –Corresponding data in a record resides in the same position in more than one array –Required in earlier programming languages that only supported array data structures –Can combine parallel elements in an object Store objects in a one-dimensional array

12 Two-Dimensional Arrays Consist of both rows and columns of elements Sometimes called tables Example declaration: –int val[][]; Example allocation: –val = new int[3][4]; Elements are identified by position in an array

13 Two-Dimensional Arrays (continued) Can be initialized from within declaration statements: –int val[][] = {{8,16,9,52}, {3,15,27,6}, {7,25,2,10}}; Number of columns need not be the same for each row May be displayed by: –Individual element notation –Using loops Usually nested loops

14

15 Two-Dimensional Array Length val.length –Provides the number of rows in the array referenced by val val[i].length –Provides the number of columns in the ith row of val array

16 Passing Two-Dimensional Arrays Identical to passing a one-dimensional array –The called method receives access to the entire array

17 Advanced Dimensioning Capabilities Can create two-dimensional arrays where each row has a different number of columns To create: –Initialize a list that explicitly lists values for each row –Or use the new operator and place values into the newly created array

18 Larger Dimensional Arrays Can have any number of array dimensions Similar to creating and allocating two-dimensional arrays Declaration: int val[][][]; val = new int[3][2][2];

19

20 Common Programming Errors Forgetting the empty bracket pairs when declaring an array’s name Declaring an array reference variable using explicit dimension sizes Using a subscript that references a nonexistent array element Not using a large enough counter value in a for loop counter to cycle through all array elements

21 Summary One-dimensional array: –Data structure –Stores list of values of same data type Array elements: –Stored in contiguous locations in memory –Referenced using the array name and a subscript Such as num[22]

22 Summary (continued) Two-dimensional array is declared by providing: –Data type –Reference variable name –Two sets of empty bracket pairs after the array’s name Arrays may be initialized when they are declared Collections framework –Set of classes providing generic data structures