SlideShare a Scribd company logo
1 of 12
Experts Of
Programming
Created By: Anonymous
What is 2-D Array?
• Array of Arrays.
• 2-D array usually represented with rows and columns
2-D Array Declaration
• We can declare 2-D array in following ways
type[][] referencevariable;
or
type referencevariable[][];
For example:
int marks[][];
Each element in the 2-D Array must be the same type.
Creation of 2-D Array
arrayreferencevariable = new type[value][value];
For example :
marks = new int[3][4];
More on 2-D Array Creation
marks = new int[][] // incorrect;
marks= new int[][4] // incorrect;
marks = new int[3][] // correct;
2-D array in form of rows and columns:
marks=new int[3][4];
Initialization of 2-D Array
• After array creation we can initialize the 2-D array like this :
• Arrayvariable[row][column]= value;
• For example lets initialize the marks array :
marks[0][0]=8; marks[0][1]=9; marks[0][2]=10; marks[0][3]=7;
8 9 10 7Row 0
Col 0 Col 1 Col 3 Col 4
12 21 30 7
31 45 10 40
Row 1
Row 2
Col 0 Col 1 Col 2 Col 3
Col 0 Col 1 Col 2 Col 3
marks[1][0]=12; marks[1][1]=21; marks[1][2]=30; marks[1][3]=7;
marks[2][0]=31; marks[2][1]=45; marks[2][2]=10; marks[2][3]=40;
8 9 10 7
12 21 30 7
31 45 10 40
Col 0 Col 2 Col 3Col 1
Row 0
Row 1
Row 2
Now if you want to access any element from 2-D array
System.Out.Println(marks[1][2]);
output = 30
System.Out.Println(marks[0][0]);
output = 8
We can also initialize the array at the time of
array creation
int[][] marks = new int{
{1,2,0,5},
{4,5,1,4},
{7,6,5,9}
}
How we can get array length
marks.length // tell us rows.
marks[0].length // tell us columns.
THANKYOU

More Related Content

What's hot

What's hot (20)

Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
List in Python
List in PythonList in Python
List in Python
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Java arrays
Java arraysJava arrays
Java arrays
 
Array ppt
Array pptArray ppt
Array ppt
 
Python set
Python setPython set
Python set
 
Java threads
Java threadsJava threads
Java threads
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
Arrays
ArraysArrays
Arrays
 
sets and maps
 sets and maps sets and maps
sets and maps
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 

Similar to Two-dimensional array in java

Similar to Two-dimensional array in java (20)

Learn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & ArraysLearn C# Programming - Nullables & Arrays
Learn C# Programming - Nullables & Arrays
 
L10 array
L10 arrayL10 array
L10 array
 
Array
ArrayArray
Array
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Array in C full basic explanation
Array in C full basic explanationArray in C full basic explanation
Array in C full basic explanation
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
7array in c#
7array in c#7array in c#
7array in c#
 
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
 
2D arrays
2D arrays2D arrays
2D arrays
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Array in Java
Array in JavaArray in Java
Array in Java
 
2D Array
2D Array 2D Array
2D Array
 
R data-structures-3
R data-structures-3R data-structures-3
R data-structures-3
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Array in c#
Array in c#Array in c#
Array in c#
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Arrays in java (signle dimensional array)
Arrays in java (signle dimensional array)Arrays in java (signle dimensional array)
Arrays in java (signle dimensional array)
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
 

Recently uploaded

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Two-dimensional array in java

  • 2. What is 2-D Array? • Array of Arrays. • 2-D array usually represented with rows and columns
  • 3. 2-D Array Declaration • We can declare 2-D array in following ways type[][] referencevariable; or type referencevariable[][]; For example: int marks[][]; Each element in the 2-D Array must be the same type.
  • 4. Creation of 2-D Array arrayreferencevariable = new type[value][value]; For example : marks = new int[3][4];
  • 5. More on 2-D Array Creation marks = new int[][] // incorrect; marks= new int[][4] // incorrect; marks = new int[3][] // correct;
  • 6. 2-D array in form of rows and columns: marks=new int[3][4];
  • 7. Initialization of 2-D Array • After array creation we can initialize the 2-D array like this : • Arrayvariable[row][column]= value; • For example lets initialize the marks array :
  • 8. marks[0][0]=8; marks[0][1]=9; marks[0][2]=10; marks[0][3]=7; 8 9 10 7Row 0 Col 0 Col 1 Col 3 Col 4 12 21 30 7 31 45 10 40 Row 1 Row 2 Col 0 Col 1 Col 2 Col 3 Col 0 Col 1 Col 2 Col 3 marks[1][0]=12; marks[1][1]=21; marks[1][2]=30; marks[1][3]=7; marks[2][0]=31; marks[2][1]=45; marks[2][2]=10; marks[2][3]=40;
  • 9. 8 9 10 7 12 21 30 7 31 45 10 40 Col 0 Col 2 Col 3Col 1 Row 0 Row 1 Row 2 Now if you want to access any element from 2-D array System.Out.Println(marks[1][2]); output = 30 System.Out.Println(marks[0][0]); output = 8
  • 10. We can also initialize the array at the time of array creation int[][] marks = new int{ {1,2,0,5}, {4,5,1,4}, {7,6,5,9} }
  • 11. How we can get array length marks.length // tell us rows. marks[0].length // tell us columns.