7.1 Arrays. 7.1.1 Introduction to arrays Any array is a collection of objects or primitives Useful when the number of reference variables is large or.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Introduction to C Programming
Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Searching and Sorting an Array 4 Searching and sorting are two fundamental algorithms often implemented with arrays –Search an array to determine the location.
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Arrays.
For use of IST410 Students only Arrays-1 Arrays. For use of IST410 Students only Arrays-2 Objectives l Declaring arrays l Instantiating arrays l Using.
©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.
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.
 2006 Pearson Education, Inc. All rights reserved Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
An Object-Oriented Approach to Programming Logic and Design Chapter 7 Arrays.
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Chapter 9 Introduction to Arrays
 2006 Pearson Education, Inc. All rights reserved Arrays and Vectors.
Arrays, Strings, and Pointers CSE 2451 Rong Shi. Arrays Store many values of the same type in adjacent memory locations Declaration [ ] Examples: – int.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Java Unit 9: Arrays Declaring and Processing Arrays.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
IE 212: Computational Methods for Industrial Engineering
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
 2006 Pearson Education, Inc. All rights reserved Arrays.
A First Book of ANSI C Fourth Edition
Chapter 8 Arrays and Strings
1 Lecture # 4. * An array is a group of contiguous or related data items that share a common name. * Each value is stored at a specific position * Position.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
DATA STRUCTURES LAB 1 TA: Nouf Al-harbi
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
Two Dimensional Arrays Found in chapter 8, Section 8.9.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
Engineering Computing I Chapter 5 Pointers and Arrays.
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.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Arrays Outline 6.1Introduction 6.2Arrays 6.3Declaring.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
© Rick Mercer Chapter 7 The Java Array Object.  Some variables store precisely one value: a double stores one floating-point number a double stores one.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Java Programming Language Lecture27- An Introduction.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
7 Arrays.
Arrays.
Presentation transcript:

7.1 Arrays

7.1.1 Introduction to arrays Any array is a collection of objects or primitives Useful when the number of reference variables is large or can’t be determined until Runtime

7.1.2 Variables in arrays An array is a collection of variables The variables are either a primitive or a reference to an object There is also a reference to the array itself

7.1.3 Index Arrays are a built-in object All members of the array are of the same type and size Accessing array members is quick and efficient

7.1.4 Arrays of primitives This example shows two arrays of primitives

7.1.5 Arrays of objects Arrays of objects are a collection of references The array variable references the array object Each member of the array is itself a reference to another object

7.2.1 Creating arrays Step 1: Declare the array reference variable int[] arrayOfInts; int arrayOfInts[]; Step 2: Create the array using the ‘new’ operator arrayOfInts = new int[5]; The array is then initialized to default values

7.2.2 Use subscripts to access elements of an array Access the members of the array using an index Index is an int The index for the first member is 0 The following code creates an array of ints, then assigns a value to the 3 rd element Int[] myArray; myArray = new int[5]; myArray[2] = 57;

7.3.1 Array of primitives Arrays of primitives can be assigned initial values when they are declared The array members can still be changed if necessary

7.3.2 Array of objects Initializing arrays of objects requires that the objects be instantiated first, ie: Account[] accountList; accountList = new Account[2]; accountList[0] = new Account(203.50); accountList[1] = new Account( );

7.4.1 Accessing array elements The index value must resolve to an int Can be an explicit value of the result of a calculation loopValue = arrayOfInts[index – 1]; System.arraycopy() can be used to copy the contents of one array to another System.arraycopy(arrayOfInts, 0, anotherArrayOfInts, 0, arrayOfInts.length);

7.4.2 Using arrays An array can be a way of passing a large number of arguments to a method Parallel arrays can be used to store related information String names = new String[20]; String addresses = new String[20]; String phone = new String[20]; Char grades = new char[20]; Array members can be searched and sorted

7.5.1 Multidimensional arrays Multidimensional arrays can be used instead of parallel arrays Declared with multiple sets of ‘[]’ int[][] multiArray = new int[20][30]; Use a separate index for each ‘dimension’ loopValue = multiArray[5][20];

7.5.2 Traversing a multidimensional array Nested ‘for’ loops can be used to index all the elements of an array public int[][] myArray = new int[4][5]; for(x = 0; x < 4; x++) { for(y = 0; y < 5; y++) { myArray[x][y] = x * y; }