Lecturer : Sakuni Sellapperuma. Introduction An array is a container object that holds a fixed number of values of a single type. The length of an array.

Slides:



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

Chapter 10 – Arrays and ArrayLists
Introduction to C Programming
Chapter 7: Arrays In this chapter, you will learn about
Chapter 8: Arrays.
Arrays.
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.
Array Yoshi. Definition An array is a container object that holds a fixed number of values of a single type. The length of an array is established when.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Arrays. Arrays  When a value is to be used in a program, a variable is declared to hold that value  What about storing the results of exams for a large.
1 11/8/06CS150 Introduction to Computer Science 1 Arrays Chapter 8 page 477 November 13, 2006.
Arrays Chapter 8 page /24/07CS150 Introduction to Computer Science 1 Arrays (8.1)  One variable that can store a group of values of the same.
Lecture 5 Arrays A way to organize data © MIT AITI 2003.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Arrays. Arrays  When a value is to be used in a program, a variable is declared to hold that value  What about storing the results of exams for a large.
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.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
“Introduction to Programming With Java” Lecture - 6 U MESH P ATIL
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.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Arrays. Arrays in Java  Arrays in Java are objects.  Like all objects are created with the new keyword.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
Pemrograman Dasar Arrays PTIIK - UB. Arrays  An array is a container object that holds a fixed number of values of a single type.  The length of an.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
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.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Chapter overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
CS 161 Introduction to Programming and Problem Solving Chapter 19 Single-Dimensional Arrays Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
CHAPTER 7: Arrays CSEB113 PRINCIPLES of PROGRAMMING CSEB134 PROGRAMMING I by Badariah Solemon 1BS (Feb 2012)
Arrays.
CS 180 Recitation 7 Arrays. Used to store similar values or objects. An array is an indexed collection of data values of the same type. Arrays are the.
Java – An Object Oriented Language CS 307 Lecture Notes Lecture Weeks 5-6 Khalid Siddiqui.
Array and String.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Arrays.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Introduction to programming in java Lecture 23 Two dimensional (2D) Arrays – Part 3.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Java Programming Language Lecture27- An Introduction.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Array in C# Array in C# RIHS Arshad Khan
Two-Dimensional Arrays
Array, Strings and Vectors
A simple way to organize data
Method Mark and Lyubo.
Java How to Program, Late Objects Version, 10/e
EKT150 : Computer Programming
Introduction To Programming Information Technology , 1’st Semester
Object Oriented Programming in java
Multidimensional Arrays
MSIS 655 Advanced Business Applications Programming
Single-Dimensional Arrays chapter6
Java SE 7 One and Multi Dimensional Arrays Module 6
Arrays in Java Prepare 1 whole yellow paper.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Presentation transcript:

Lecturer : Sakuni Sellapperuma

Introduction An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. 2Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]

Introduction cont… An array can hold either primitive or reference type data. An array has its size that is known as array length. An array knows only its type that it contains. Array type is checked at the compile-time. Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]3

Disadvantages An array has fixed size. An array can hold only one type of data (either primitive or reference). Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]4

Creating Arrays There are 3 steps when creating an array Declare an Array Construct an Array Initialize an Array Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]5

Declare Arrays Declare an array variable by specifying the type of data to be stored, followed by square brackets [] DataType[] variableName; DataType variableName[]; Ex : int marks[]; int[] marks; Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]6

Construct Arrays Use ‘new’ keyword when constructing arrays. Mention the data type, and the array size in between square brackets. DataType objName[] = new DataType[Size]; Ex : 1. int[] marks; marks = new int[10]; String[] names = new String[3]; Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]7

Initialize Array Java arrays are zero based. By using the index you can access the array. Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]8

Initialize Array int marks[] = new int[1]; marks[0] = 100; char chr[] = new char[2]; chr[0] = 65; chr[1] = 'D'; String names[] = new String[3]; names[0] = "Java"; names[1] = "SCJP"; names[2] = "ESOFT“; Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]9

Anonymous Array Java can directly create an array and initialize values. int[] numbers = { 2, 3, 4, 5, 6, 7, 8 }; Do not need ‘new’ keyword. Ex: new int[] { 11, 12, 13, 14, 15, 16, 17}; numbers = new int[] { 11, 12, 13, 14, 15, 16, 17 }; int[] anonymousarr = { 11, 12, 13, 14, 15, 16} ; Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]10

Copy Array Data The System class has an arraycopy method that you can use to copy data efficiently from one array into another: public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]11

Copying Array char[] copyFrom = {'e', 'c', 'a', 'f', 'f', 'e', 'i', 'n', 'a', 't', 'e'}; char[] copyTo = new char[7]; System.arraycopy(copyFrom, 1, copyTo, 0, 7); Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]12

Multi Dimensional Arrays Java, as with most languages, supports multi- dimensional arrays. Ex : 2 D Array 3 D Array In this lesson we discuss about 2-dimensional arrays. But same principles apply for higher dimensions also. Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]13

2 Dimensional Arrays 2-D arrays are usually represent a row-column approach on paper. The term "rows" and "columns" are used in computing. Ex : int[][] a2 = new int[10][5]; Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]14

Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]15

End of Chapter 01 Part 05 Thank You! 16Sakuni Sellapperuma [Bsc. Spec.(Hon) in IT, SCJP]