Arrays.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Introduction to Java Objects CSIS 3701: Advanced Object Oriented Programming.
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Chapter 10 Arrays. Topics Declaring and instantiating arrays Array element access Arrays of objects Arrays as method parameters Arrays as return values.
CMPT 225 ADT List using Dynamic arrays A dynamic data structure is one that changes size, as needed, as items are inserted or removed The Java ArrayList.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
Strings A string is a sequence of characters that is treated as a single value. Strings are objects. We have been using strings all along. For example,
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
CSC 533: Programming Languages Spring 2016
Object Lifetime and Pointers
Pointers and Dynamic Arrays
Data Types In Text: Chapter 6.
Arrays Chapter 7.
CSC 533: Programming Languages Spring 2015
Array Review CS 139 – November 28, 2007.
GC211 Data Structure Lecture 1 Sara Alhajjam.
Chapter 6 – Data Types CSCE 343.
Computer Science 210 Computer Organization
Characters and Strings
Chapter 6: Data Types Lectures # 10.
Game Extras Pepper.
CS230 Tutorial Week 3.
Java Review: Reference Types
Data Representation Methods
LINKED LISTS CSCD Linked Lists.
An Introduction to Java – Part I
Computer Science 210 Computer Organization
An Introduction to Java – Part I, language basics
Array Review CS 139 – November 28, 2007.
Unit-1 Introduction to Java
The University of Adelaide, School of Computer Science
Pointer Data Type and Pointer Variables III
Introduction To Programming Information Technology , 1’st Semester
Object Oriented Programming in java
Arrays .
By Hector M Lugo-Cordero September 17, 2008
CS2011 Introduction to Programming I Arrays (I)
MSIS 655 Advanced Business Applications Programming
Arrays Chapter 7.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Assessment – Java Basics: Part 1
ArrayLists 22-Feb-19.
C++ Programming ㅎㅎ String OOP Class Constructor & Destructor.
Object Oriented Programming
Array Review CS 139 – November 28, 2007.
Pointer Variables A pointer is a variable that contains a memory address The address is commonly the location of another variable in memory This pointer.
Chapter 9: Pointers and String
Java: Variables, Input and Arrays
CSC Java Programming, Spring, 2012
Quick Review EECS May 2019.
Characters and Strings
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
String Class.
Introduction to java Part I By Shenglan Zhang.
Arrays Introduction to Arrays Reading for this Lecture:
CSC 533: Programming Languages Spring 2019
Classes and Objects Object Creation
Run-time environments
COS 151 Bootcamp – Week 4 Department of Computer Science
SPL – PS2 C++ Memory Handling.
CSE 303 Concepts and Tools for Software Development
Presentation transcript:

Arrays

Copy of a Variable Two variables are independent of each other if their values can change independently of each other

Copying an Array (1)

Copying an Array (2) The array element identified by the name a[0] is the same array element that is identified by the name b[0] The statement b = a; did not make a (true) copy of an array Aliasing = using different names to access the same variable

Copying an Array (3)

Copying an Array (4) In Java, we can change an existing array reference to make it point to a different set of array elements The Java programming system has a built-in utility that reclaim the memory cells used by inaccessible variables (= garbage)

Copying an Array (5) In order to copy an array in Java, we must: Create another array (of the same size) using the new operator Copy the elements (one by one) from the old array into the new array.

Copying an Array (6)

Static and dynamic arrays (1) Static array = an array name that refers to an array where the number of elements in the array is constant (fixed) Dynamic array = an array name that refers to an array where the number of elements in the array can be changed

Static and dynamic arrays (2) We first create a new array of the desired length Then, we must copy the elements from the old array into the newly created array Finally, we make the variable a point to the new array.

Static and dynamic arrays (3)

Static and dynamic arrays (4)

String Array and Command Line Argument

Command arguments (1) Command = an application program that is being executed Argument = the words that follow the command

Command arguments (2)

Command arguments (3)

Command arguments (4)

Converting String to array of char and vice versa (1)

Converting String to array of char and vice versa (2)

Converting String to array of char and vice versa (3)

Example