SlideShare a Scribd company logo
Java Programming Language SE – 6
Module 5 : Arrays
www.webstackacademy.com
Objectives
● Declare and create arrays of primitive, class, or array types
● Explain why elements of an array are initialized
● Explain how to initialize the elements of an array
● Determine the number of elements in an array
● Create a multidimensional array
● Write code to copy array values from one array to another
www.webstackacademy.com
Creating Arrays
Use the new keyword to create an array object.
For example, a primitive (char) array:
public char[] createArray() {
char[] s;
s = new char[26];
for ( int i=0; i<26; i++ ) {
s[i] = (char) (’A’ + i);
}
return s;
}
www.webstackacademy.com
Creating an Array of
Character Primitives
www.webstackacademy.com
Creating Reference Arrays
Another example, an object array:
public Point[] createArray() {
Point[] p;
p = new Point[10];
for ( int i=0; i<10; i++ ) {
p[i] = new Point(i, i+1);
}
return p;
}
www.webstackacademy.com
Initializing Arrays
● Initialize an array element.
● Create an array with initial values.
String[] names;
names = new String[3];
names[0] = "Georgianna";
names[1] = "Jen";
names[2] = "Simon";
www.webstackacademy.com
Multidimensional Arrays
● Arrays of arrays:
int[][] twoDim = new int[4][];
twoDim[0] = new int[5];
twoDim[1] = new int[5];
int[][] twoDim = new int[][4]; // illegal
● Array of four arrays of five integers each:
int[][] twoDim = new int[4][5];
www.webstackacademy.com
Array Bounds
All array subscripts begin at 0:
public void printElements(int[] list) {
for (int i = 0; i < list.length; i++) {
System.out.println(list[i]);
}
}
www.webstackacademy.com
Using the Enhanced
for Loop
● Java 2 Platform, Standard Edition (J2SETM) version 5.0 introduced
an enhanced for loop for iterating over arrays:
public void printElements(int[] list) {
for ( int element : list ) {
System.out.println(element);
}
}
www.webstackacademy.com
Array Resizing
● You cannot resize an array.
● You can use the same reference variable to refer to an entirely new
array, such as:
int[] myArray = new int[6];
myArray = new int[10];
www.webstackacademy.com
Copying Arrays
The System.arraycopy() method to copy arrays is:
//original array
int[] myArray = { 1, 2, 3, 4, 5, 6 };
// new larger array
int[] hold = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
// copy all of the myArray array to the hold
// array, starting with the 0th index
System.arraycopy(myArray, 0, hold, 0, myArray.length);
www.webstackacademy.com
Web Stack Academy (P) Ltd
#83, Farah Towers,
1st floor,MG Road,
Bangalore – 560001
M: +91-80-4128 9576
T: +91-98862 69112
E: info@www.webstackacademy.com

More Related Content

What's hot (20)

PDF
Towards hasktorch 1.0
Junji Hashimoto
 
PPTX
Arrays in Data
Afzal Badshah
 
PPTX
Functional Programming, simplified
Naveenkumar Muguda
 
PPTX
Swift 0x0c 서브스크립트
Hyun Jin Moon
 
PDF
Numpy Meetup 07/02/2013
Francesco
 
PDF
1 sample16c132 java-programming
Mary Jones
 
DOCX
Lab 6 (1)
ssuser45ffd4
 
KEY
Nu program language on Shibuya.lisp#5 LT
Yuumi Yoshida
 
PPTX
Operators and expression in c++
ThamizhselviKrishnam
 
PPTX
Queue
Sonali Soni
 
PPT
Arrays
afzal pa
 
PDF
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
PDF
STL
Naoya Nakazawa
 
PDF
OCamlOScope: a New OCaml API Search
Jun Furuse
 
PPTX
Pf presntation
Roshan Roshan Ansari
 
PPT
Review functions
Kgr Sushmitha
 
DOCX
2 a networkflow
Aravindharamanan S
 
PPTX
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
ODP
Functors, applicatives, monads
rkaippully
 
PPTX
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Towards hasktorch 1.0
Junji Hashimoto
 
Arrays in Data
Afzal Badshah
 
Functional Programming, simplified
Naveenkumar Muguda
 
Swift 0x0c 서브스크립트
Hyun Jin Moon
 
Numpy Meetup 07/02/2013
Francesco
 
1 sample16c132 java-programming
Mary Jones
 
Lab 6 (1)
ssuser45ffd4
 
Nu program language on Shibuya.lisp#5 LT
Yuumi Yoshida
 
Operators and expression in c++
ThamizhselviKrishnam
 
Queue
Sonali Soni
 
Arrays
afzal pa
 
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
OCamlOScope: a New OCaml API Search
Jun Furuse
 
Pf presntation
Roshan Roshan Ansari
 
Review functions
Kgr Sushmitha
 
2 a networkflow
Aravindharamanan S
 
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Functors, applicatives, monads
rkaippully
 
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 

Similar to Core Java Programming Language (JSE) : Chapter V - Arrays (20)

PPTX
Arrays in java
bhavesh prakash
 
DOCX
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
PDF
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
PPTX
CH1 ARRAY (1).pptx
AnkitaVerma776806
 
PDF
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
PPTX
SessionPlans_f3efa1.6 Array in java.pptx
businessmarketing100
 
PDF
Lecture 6
Debasish Pratihari
 
PPTX
Unit-2.Arrays and Strings.pptx.................
suchitrapoojari984
 
DOCX
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 
PPTX
arrays in c# including Classes handling arrays
JayanthiM19
 
PDF
4java Basic Syntax
Adil Jafri
 
PDF
Java Lab Manual
Naveen Sagayaselvaraj
 
PPT
Arrays in c programing. practicals and .ppt
Carlos701746
 
PDF
Arrays
Steven Wallach
 
PDF
Object Oriented Programming - 5.1. Array
AndiNurkholis1
 
DOC
Arrays In General
martha leon
 
PPTX
arrays-120712074248-phpapp01
Abdul Samee
 
PPTX
DOC-20240812-WA0000 array string and.pptx
PanjatcharamVg
 
PPT
Md05 arrays
Rakesh Madugula
 
Arrays in java
bhavesh prakash
 
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
CH1 ARRAY (1).pptx
AnkitaVerma776806
 
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
SessionPlans_f3efa1.6 Array in java.pptx
businessmarketing100
 
Lecture 6
Debasish Pratihari
 
Unit-2.Arrays and Strings.pptx.................
suchitrapoojari984
 
Arraysnklkjjkknlnlknnjlnjljljkjnjkjn.docx
pranauvsps
 
arrays in c# including Classes handling arrays
JayanthiM19
 
4java Basic Syntax
Adil Jafri
 
Java Lab Manual
Naveen Sagayaselvaraj
 
Arrays in c programing. practicals and .ppt
Carlos701746
 
Arrays
Steven Wallach
 
Object Oriented Programming - 5.1. Array
AndiNurkholis1
 
Arrays In General
martha leon
 
arrays-120712074248-phpapp01
Abdul Samee
 
DOC-20240812-WA0000 array string and.pptx
PanjatcharamVg
 
Md05 arrays
Rakesh Madugula
 
Ad

More from WebStackAcademy (20)

PDF
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
PDF
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
PDF
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
PDF
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
PDF
Webstack Academy - Internship Kick Off
WebStackAcademy
 
PDF
Building Your Online Portfolio
WebStackAcademy
 
PDF
Front-End Developer's Career Roadmap
WebStackAcademy
 
PDF
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
PDF
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
PDF
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
PDF
Angular - Chapter 5 - Directives
WebStackAcademy
 
PDF
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
PDF
Angular - Chapter 3 - Components
WebStackAcademy
 
PDF
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
 
PDF
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
PDF
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
PDF
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
Webstack Academy - Internship Kick Off
WebStackAcademy
 
Building Your Online Portfolio
WebStackAcademy
 
Front-End Developer's Career Roadmap
WebStackAcademy
 
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
Angular - Chapter 5 - Directives
WebStackAcademy
 
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Angular - Chapter 3 - Components
WebStackAcademy
 
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Angular - Chapter 1 - Introduction
WebStackAcademy
 
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Ad

Recently uploaded (20)

PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 

Core Java Programming Language (JSE) : Chapter V - Arrays