SlideShare a Scribd company logo
4
Most read
10
Most read
12
Most read
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

PPT
Two dimensional array
PDF
Java data types, variables and jvm
PPTX
Java input
PPTX
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPS
Introduction to class in java
PPTX
concept of Array, 1D & 2D array
PPT
Data types
Two dimensional array
Java data types, variables and jvm
Java input
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Introduction to class in java
concept of Array, 1D & 2D array
Data types

What's hot (20)

PPTX
Java Stack Data Structure.pptx
PPTX
Arrays in Java
PPTX
2D Array
PPTX
This keyword in java
PDF
Command line-arguments-in-java-tutorial
PPTX
Constructor and Destructor in c++
PPTX
Classes, objects in JAVA
PPTX
Array in c#
PPTX
PPTX
Constructor in java
PPT
Working with frames
PPT
Final keyword in java
PPTX
constructors in java ppt
PPTX
Introduction to Array ppt
PPTX
PPTX
Doubly Linked List
PPTX
Java arrays
PPTX
Python dictionary
PPTX
Control Statements in Java
PPT
Array in Java
Java Stack Data Structure.pptx
Arrays in Java
2D Array
This keyword in java
Command line-arguments-in-java-tutorial
Constructor and Destructor in c++
Classes, objects in JAVA
Array in c#
Constructor in java
Working with frames
Final keyword in java
constructors in java ppt
Introduction to Array ppt
Doubly Linked List
Java arrays
Python dictionary
Control Statements in Java
Array in Java
Ad

Similar to Two-dimensional array in java (20)

PPTX
Understanding 2D Array with example in programming language c
PPTX
PDF
Learn C# Programming - Nullables & Arrays
PDF
arrays-130116232821-phpapp02.pdf
PPTX
TwoDArrays which can easily help you understand java 2D arrays.pptx
PPTX
How to create a two-dimensional array in java
PPTX
arrays.pptx
PPTX
OOPs with java
PPT
L10 array
PPT
Data Structure Midterm Lesson Arrays
PPTX
Two dimensional Array
PPT
Visula C# Programming Lecture 5
PDF
Arrays a detailed explanation and presentation
PDF
Java arrays
PPSX
dizital pods session 6-arrays.ppsx
PPTX
dizital pods session 6-arrays.pptx
PDF
Lecture06 computer applicationsie1_dratifshahzad
PPTX
arrays in c# including Classes handling arrays
PPT
Java: Introduction to Arrays
PPTX
13 - opp presentation Pointer to 2d arrays and DMA.pptx
Understanding 2D Array with example in programming language c
Learn C# Programming - Nullables & Arrays
arrays-130116232821-phpapp02.pdf
TwoDArrays which can easily help you understand java 2D arrays.pptx
How to create a two-dimensional array in java
arrays.pptx
OOPs with java
L10 array
Data Structure Midterm Lesson Arrays
Two dimensional Array
Visula C# Programming Lecture 5
Arrays a detailed explanation and presentation
Java arrays
dizital pods session 6-arrays.ppsx
dizital pods session 6-arrays.pptx
Lecture06 computer applicationsie1_dratifshahzad
arrays in c# including Classes handling arrays
Java: Introduction to Arrays
13 - opp presentation Pointer to 2d arrays and DMA.pptx
Ad

Recently uploaded (20)

PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
5 Lead Qualification Frameworks Every Sales Team Should Use
PDF
AI in Product Development-omnex systems
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administration Chapter 2
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPTX
Presentation of Computer CLASS 2 .pptx
PPTX
Mini project ppt template for panimalar Engineering college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Understanding Forklifts - TECH EHS Solution
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
medical staffing services at VALiNTRY
DOCX
The Five Best AI Cover Tools in 2025.docx
PDF
Digital Strategies for Manufacturing Companies
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPT
JAVA ppt tutorial basics to learn java programming
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
5 Lead Qualification Frameworks Every Sales Team Should Use
AI in Product Development-omnex systems
L1 - Introduction to python Backend.pptx
Odoo POS Development Services by CandidRoot Solutions
System and Network Administration Chapter 2
Materi_Pemrograman_Komputer-Looping.pptx
Presentation of Computer CLASS 2 .pptx
Mini project ppt template for panimalar Engineering college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Understanding Forklifts - TECH EHS Solution
PTS Company Brochure 2025 (1).pdf.......
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
medical staffing services at VALiNTRY
The Five Best AI Cover Tools in 2025.docx
Digital Strategies for Manufacturing Companies
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
JAVA ppt tutorial basics to learn java programming
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Upgrade and Innovation Strategies for SAP ERP Customers

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.