SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler offline
Core Java

Debasish Pratihari

Array :



In Java arrays are objects that represent a
group of contiguous memory locations of the
same type and referred to by the same name.



The element type for an array can be any
primitive data type or object.



All Java arrays are technically one-dimensional.
Two-dimensional arrays are arrays of arrays.



Declaring an array does not create an array
object or allocate space in memory; it creates a
variable with a reference to an array



Array variable declarations must indicate a
dimension by using []



All arrays are zero-based



Arrays must be indexed by int values or byte,
short or char values (as these can be promoted
to int)



Using a long index value to access an array
causes a compile error



Attempting to access an array with an index less
than 0 or greater than the length of the array
causes an ArrayIndexOutOfBoundsException
to be thrown at runtime



Since arrays are Objects they can be initialized
using the new operator



When created, arrays are automatically
initialized with the default value of their type



Array references declared as members are
initialized to null BUT array references declared
in methods are not initialized

Lecture/core/array/06

Page #1

feel the Technology…
Core Java

Debasish Pratihari

Examples of valid array declarations :



String[]s;



String s[];



String[][]s;



String s[][];



String[] s[];

Initializing Array :












String[ ] s = new String[100]; // default values: null
boolean[] b = new boolean[4]; // default values: false
int i[ ]= new int[5];
int[][] i = new int[10][10];
// default values: 0
String[] oneDimArray = { "abc","def","xyz" };
int[] array = null;
int[][] twoDimArray = { {1,2,3}, {4,5,6}, {7,8,9} };
int[] a = { 1, primes[2], c, (int)Math.pow(2,2) };
int[] arr = new int[] {1,2,3};
int[][] myArray = new int[5][];
int arrSize = 100;
String[] myArray = new String[arrSize];

Illegal Initialization of Array :






String[5] s;
int[] array = new int[];
int[][] myArray = new int[][5];
String[] s;
s = { "Lakshya", "debasish", "java"};

Lecture/core/array/06

Page #2

feel the Technology…
Core Java

Debasish Pratihari

Finding length of an Array :



Arrays have a length data field (read only),
specifying the number of elements in the array.



The length data field can be accessed through
the dot operator.



The bounds of an array are integers between 0
and length – 1



Example
for ( int k=0; k < a.length ; k++ )
System.out.println( a[ k ] );

Multidimensional Arrays:


Multidimensional arrays are implemented as
arrays of arrays. Multidimensional arrays are
declared by appending the appropriate number
of bracket pairs after the array name.



The number of elements in each direction need
not be specified in the declaration.



The number of elements in each direction need
not be equal.

Example of irregular Array :

int[][] irregular = { { 1 },
{ 2, 3 },
{ 4, 5, 6, 7 },
{0}
};

Lecture/core/array/06

Page #3

feel the Technology…
Core Java

Debasish Pratihari

An Example -Triangle Array :
Output

int[][] triangle = new int[10][];
for ( int j = 0; j<triangle.length ; j++ )
triangle[ j ] = new int[ j + 1 ];
for ( int i = 0 ; i < triangle.length ; i++ )
{
for ( int j = 0 ; j < triangle[i].length ; j++ )
System.out.print( triangle[i][j] + " " );
System.out.println();
}

0
00
000
0000
00000
000000
0000000
00000000
000000000
0000000000

Coping Array :
25% 



Arrays can be copied using the Java System
method arraycopy():
Signature:public static native void
arraycopy(Object src, int src_position, Object
dst, int dst_position, int length)
Parameters:
src - the source array.
src_position - start position (first cell to copy) in the
source array.
dst - the destination array.
dst_position - start position in the destination array.
length - the number of array elements to be copied.



By default, all Java arrays support the clone
method.

Things to Remember :


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.



Each item in an array is called an element



each element is accessed by its numerical
index.

Lecture/core/array/06

Page #4

feel the Technology…

Mais conteúdo relacionado

Mais procurados

Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-stringsPrincess Sam
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | EdurekaEdureka!
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysMartin Chapman
 
Java Arrays
Java ArraysJava Arrays
Java ArraysOXUS 20
 
7array in c#
7array in c#7array in c#
7array in c#Sireesh K
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in javaTalha mahmood
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#Umar Farooq
 
Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuplesAbed Bukhari
 
Arrays in python
Arrays in pythonArrays in python
Arrays in pythonmoazamali28
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaEdureka!
 

Mais procurados (20)

Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
 
array
array array
array
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
7array in c#
7array in c#7array in c#
7array in c#
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in java
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuples
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 

Destaque

Carol Judge, Warwickshire County Council
Carol Judge, Warwickshire County CouncilCarol Judge, Warwickshire County Council
Carol Judge, Warwickshire County CouncilPaul McElvaney
 
Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...
Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...
Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...Paul McElvaney
 
香港六合彩
香港六合彩香港六合彩
香港六合彩wejia
 
Reviewing Screen-Based Content
Reviewing Screen-Based ContentReviewing Screen-Based Content
Reviewing Screen-Based ContentRhonda Bracey
 
Paragraphs and topic sentences
Paragraphs and topic sentencesParagraphs and topic sentences
Paragraphs and topic sentencesSussan Roo
 
عرض ملتقى النهائي جديد
عرض ملتقى النهائي جديدعرض ملتقى النهائي جديد
عرض ملتقى النهائي جديدsabah alharby
 
クラウド
クラウドクラウド
クラウドyuu_2003
 
Systems engineering leidraad se gww door ms
Systems engineering leidraad se gww door msSystems engineering leidraad se gww door ms
Systems engineering leidraad se gww door msMarcel Seijner
 
Learning Pool Social Care Webinar Presentation
Learning Pool Social Care Webinar PresentationLearning Pool Social Care Webinar Presentation
Learning Pool Social Care Webinar PresentationPaul McElvaney
 
Worksheet
WorksheetWorksheet
WorksheetNg Lim
 
Learning pool community rewards
Learning pool community rewardsLearning pool community rewards
Learning pool community rewardsPaul McElvaney
 
Online Public Relations
Online Public RelationsOnline Public Relations
Online Public RelationsSjef Kerkhofs
 
MISIÓN INTERCULTURALIDAD - 1E-A
MISIÓN INTERCULTURALIDAD - 1E-AMISIÓN INTERCULTURALIDAD - 1E-A
MISIÓN INTERCULTURALIDAD - 1E-AJuan Serrano Pérez
 
Adding A Link To A Flick’R Photo
Adding A Link To A Flick’R PhotoAdding A Link To A Flick’R Photo
Adding A Link To A Flick’R PhotoLutie
 

Destaque (20)

Carol Judge, Warwickshire County Council
Carol Judge, Warwickshire County CouncilCarol Judge, Warwickshire County Council
Carol Judge, Warwickshire County Council
 
Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...
Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...
Learning Pool's Elaine Walton & Dave Briggs on 'E-learning for Councillors an...
 
Reed business preso
Reed business presoReed business preso
Reed business preso
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
 
Reviewing Screen-Based Content
Reviewing Screen-Based ContentReviewing Screen-Based Content
Reviewing Screen-Based Content
 
Nilga Feb 2009
Nilga Feb 2009Nilga Feb 2009
Nilga Feb 2009
 
Paragraphs and topic sentences
Paragraphs and topic sentencesParagraphs and topic sentences
Paragraphs and topic sentences
 
عرض ملتقى النهائي جديد
عرض ملتقى النهائي جديدعرض ملتقى النهائي جديد
عرض ملتقى النهائي جديد
 
Lezing abc
Lezing abcLezing abc
Lezing abc
 
クラウド
クラウドクラウド
クラウド
 
Systems engineering leidraad se gww door ms
Systems engineering leidraad se gww door msSystems engineering leidraad se gww door ms
Systems engineering leidraad se gww door ms
 
Scotweb Presentation
Scotweb PresentationScotweb Presentation
Scotweb Presentation
 
Learning Pool Social Care Webinar Presentation
Learning Pool Social Care Webinar PresentationLearning Pool Social Care Webinar Presentation
Learning Pool Social Care Webinar Presentation
 
Worksheet
WorksheetWorksheet
Worksheet
 
Learning pool community rewards
Learning pool community rewardsLearning pool community rewards
Learning pool community rewards
 
Microcamp Milano
Microcamp MilanoMicrocamp Milano
Microcamp Milano
 
Online Public Relations
Online Public RelationsOnline Public Relations
Online Public Relations
 
MISIÓN INTERCULTURALIDAD - 1E-A
MISIÓN INTERCULTURALIDAD - 1E-AMISIÓN INTERCULTURALIDAD - 1E-A
MISIÓN INTERCULTURALIDAD - 1E-A
 
Lecture 16
Lecture 16Lecture 16
Lecture 16
 
Adding A Link To A Flick’R Photo
Adding A Link To A Flick’R PhotoAdding A Link To A Flick’R Photo
Adding A Link To A Flick’R Photo
 

Semelhante a Lecture 6

Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsKuntal Bhowmick
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsKuntal Bhowmick
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................suchitrapoojari984
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arraysJayanthiM19
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injavairdginfo
 
Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...ssuser6478a8
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.pptcoding9
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxrohinitalekar1
 

Semelhante a Lecture 6 (20)

Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Arrays
ArraysArrays
Arrays
 
CH1 ARRAY (1).pptx
CH1 ARRAY (1).pptxCH1 ARRAY (1).pptx
CH1 ARRAY (1).pptx
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
2 arrays
2   arrays2   arrays
2 arrays
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
Arrays in java.pptx
Arrays in java.pptxArrays in java.pptx
Arrays in java.pptx
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
 
javaArrays.pptx
javaArrays.pptxjavaArrays.pptx
javaArrays.pptx
 
Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 

Mais de Debasish Pratihari (19)

Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Lecture 20
Lecture 20Lecture 20
Lecture 20
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
Lecture 14
Lecture 14Lecture 14
Lecture 14
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture25
Lecture25Lecture25
Lecture25
 

Último

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Lecture 6

  • 1. Core Java Debasish Pratihari Array :  In Java arrays are objects that represent a group of contiguous memory locations of the same type and referred to by the same name.  The element type for an array can be any primitive data type or object.  All Java arrays are technically one-dimensional. Two-dimensional arrays are arrays of arrays.  Declaring an array does not create an array object or allocate space in memory; it creates a variable with a reference to an array  Array variable declarations must indicate a dimension by using []  All arrays are zero-based  Arrays must be indexed by int values or byte, short or char values (as these can be promoted to int)  Using a long index value to access an array causes a compile error  Attempting to access an array with an index less than 0 or greater than the length of the array causes an ArrayIndexOutOfBoundsException to be thrown at runtime  Since arrays are Objects they can be initialized using the new operator  When created, arrays are automatically initialized with the default value of their type  Array references declared as members are initialized to null BUT array references declared in methods are not initialized Lecture/core/array/06 Page #1 feel the Technology…
  • 2. Core Java Debasish Pratihari Examples of valid array declarations :  String[]s;  String s[];  String[][]s;  String s[][];  String[] s[]; Initializing Array :            String[ ] s = new String[100]; // default values: null boolean[] b = new boolean[4]; // default values: false int i[ ]= new int[5]; int[][] i = new int[10][10]; // default values: 0 String[] oneDimArray = { "abc","def","xyz" }; int[] array = null; int[][] twoDimArray = { {1,2,3}, {4,5,6}, {7,8,9} }; int[] a = { 1, primes[2], c, (int)Math.pow(2,2) }; int[] arr = new int[] {1,2,3}; int[][] myArray = new int[5][]; int arrSize = 100; String[] myArray = new String[arrSize]; Illegal Initialization of Array :     String[5] s; int[] array = new int[]; int[][] myArray = new int[][5]; String[] s; s = { "Lakshya", "debasish", "java"}; Lecture/core/array/06 Page #2 feel the Technology…
  • 3. Core Java Debasish Pratihari Finding length of an Array :  Arrays have a length data field (read only), specifying the number of elements in the array.  The length data field can be accessed through the dot operator.  The bounds of an array are integers between 0 and length – 1  Example for ( int k=0; k < a.length ; k++ ) System.out.println( a[ k ] ); Multidimensional Arrays:  Multidimensional arrays are implemented as arrays of arrays. Multidimensional arrays are declared by appending the appropriate number of bracket pairs after the array name.  The number of elements in each direction need not be specified in the declaration.  The number of elements in each direction need not be equal. Example of irregular Array : int[][] irregular = { { 1 }, { 2, 3 }, { 4, 5, 6, 7 }, {0} }; Lecture/core/array/06 Page #3 feel the Technology…
  • 4. Core Java Debasish Pratihari An Example -Triangle Array : Output int[][] triangle = new int[10][]; for ( int j = 0; j<triangle.length ; j++ ) triangle[ j ] = new int[ j + 1 ]; for ( int i = 0 ; i < triangle.length ; i++ ) { for ( int j = 0 ; j < triangle[i].length ; j++ ) System.out.print( triangle[i][j] + " " ); System.out.println(); } 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 Coping Array : 25%    Arrays can be copied using the Java System method arraycopy(): Signature:public static native void arraycopy(Object src, int src_position, Object dst, int dst_position, int length) Parameters: src - the source array. src_position - start position (first cell to copy) in the source array. dst - the destination array. dst_position - start position in the destination array. length - the number of array elements to be copied.  By default, all Java arrays support the clone method. Things to Remember :  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.  Each item in an array is called an element  each element is accessed by its numerical index. Lecture/core/array/06 Page #4 feel the Technology…