Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

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.
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
CSCI 1100/ , 6.2, 6.4 April 12, 15, 17.
Chapter 10 Introduction to Arrays
Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 7.1 Introduction Arrays –Data structures which reference one or more value –All items must have same data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Arrays Clark Savage Turner, J.D., Ph.D. Copyright © 2000 by C Scheftic. All rights reserved. These notes do rely heavily.
Chapter 7 Arrays. © 2004 Pearson Addison-Wesley. All rights reserved7-2 Arrays Arrays are objects that help us organize large amounts of information Chapter.
1 More on Arrays Passing arrays to or from methods Arrays of objects Command line arguments Variable length parameter lists Two dimensional arrays Reading.
1 Arrays b An array is an ordered list of values An array of size N is indexed from zero to N-1 scores.
©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.
Aalborg Media Lab 28-Jun-15 Software Design Lecture 8 “Arrays”
Arrays in Java Selim Aksoy Bilkent University Department of Computer Engineering
 2003 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Arrays Introduction to Computers and Programming in.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Chapter 9 Introduction to Arrays
 Pearson Education, Inc. All rights reserved 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.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Chapter 7 Arrays. © 2004 Pearson Addison-Wesley. All rights reserved7-2 Arrays Arrays are objects that help us organize large amounts of information Chapter.
1 Dr. Seuss again: "Too Many Daves"  Did I ever tell you that Mrs. McCave Had twenty-three sons, and she named them all Dave?  Well, she did. And that.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
 2005 Pearson Education, Inc. All rights reserved. 1 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.
Chapter 8: Arrays.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005.
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.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 6: Arrays Presentation slides for Java Software Solutions for AP* Computer Science 3rd Edition.
8-1 Chapter 8: Arrays Arrays are objects that help us organize large amounts of information Today we will focuses on: –array declaration and use –bounds.
© 2004 Pearson Addison-Wesley. All rights reserved October 13, D Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor:
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
CSE 501N Fall ‘09 08: Arrays 22 September 2009 Nicholas Leidenfrost.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 7 Arrays 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
OBJECTS FOR ORGANIZING DATA -- As our programs get more sophisticated, we need assistance organizing large amounts of data. : array declaration and use.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
Arrays.
Two Dimensional Arrays Found in chapter 8, Section 8.9.
1 Objects for Organizing Data -- Introduction zAs our programs get more sophisticated, we need assistance organizing large amounts of data zChapter 6 focuses.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Two Dimensional Arrays. Students will be able to: code algorithms to solve two- dimensional array problems. use 2-D arrays in programs. pass two-use 2-D.
1 Arrays Chapter 8. Objectives You will be able to Use arrays in your Java programs to hold a large number of data items of the same type. Initialize.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Arrays. Arrays are objects that help us organize large amounts of information.
 2005 Pearson Education, Inc. All rights reserved Arrays.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Chapter 7 Arrays…. 7-2 Arrays An array is an ordered list of values An array of size N is indexed from.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Lecture 5 array declaration and instantiation array reference
Arrays of Objects October 9, 2006 ComS 207: Programming I (in Java)
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Chapter VII: Arrays.
© 2016 Pearson Education, Ltd. All rights reserved.
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
MSIS 655 Advanced Business Applications Programming
Arrays of Objects October 8, 2007 ComS 207: Programming I (in Java)
Arrays.
Presentation transcript:

Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare variables for each piece of data.

 Arrays solve this problem  Letting us declare one variable.  This can hold multiple accessible values. Arrays

Array Indexing  An array is a list of values.  Each value is stored at a specific, position.  To access a value, we use the name of the array.

Array Indexing  The total of elements is called the size.  An array of size “N” is indexed from 0 to N-1.

Declaring and using arrays  In Java, arrays are objects.  To create an array, the reference must be declared.  The array can then be created using the new operator.

Code Example: int [ ] height = new int [10] ;  The variable height is declared to be an array.  The creation of height, using the new operator.

[ ] Square Brackets  The square brackets used to indicate the index.  The index performs automatic bounds checking.  Bounds checking ensures that the index is in the range.

Example:  An array called prices is created with 25 elements.  The value of the index is checked from 0 to 24.  Otherwise an exception is called. “ ArrayIndexOutOfBoundsException.”

length The size of the array is held in a constant called length. After the array prices is created with 25 elements, the constant prices.length contains the value 25.

Example: for ( int i = 0; i < prices.length; i++ ) { System.out.println( prices[ i ] ); }

Array syntax First is to associate the brackets with the type of values stored in the array: int [ ] grades ; Second is to associate the brackets with the name of the array: int grades [ ] ;

Initializing arrays A technique for instantiating arrays is using an initializer list, which provides the initial values for the array. The items in an initializer list are separated by commas and delimited by braces. The size of the array is determined by the number of items.

Example of initializer list When an initializer list is used, the new operator is not used. This declaration instantiates the array grades as an array of six integers, indexed from 0 to 5: int [ ] grades = { 87, 98, 69, 99, 88, 76 }

Arrays as parameters Because an array is an object, when an array is passed as a parameter, a copy of the reference to the original array is passed. A method that receives an array as a parameter can permanently change an element of the array because it is referring to the original value.

Arrays of objects Arrays store primitive types such as integers and characters. Arrays can also store references to objects as elements. An array could contain objects that consist of several variables and the methods that use them.

Example: for ( int port = 0; port <= 4350; port++ ) { try { ServerSocket server = new ServerSocket( port ); } catch (IOException e) { System.out.println( “There is a server on port: “ + port + “. “ );

Arrays of string objects The variable words is an array of references to String objects. String [ ] words = new String [ 25 ] ; The new operator in the declaration instantiates the array and reserves space for 25 String references.

Two-dimensional arrays Two-dimensional array has values in two directions, which are often represented as the rows and columns of a table. The type of a two-dimensional array that stores integers is: int [ ] [ ] ;