- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Jagged Array in Java
Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating the concept of jagged array.
Example
public class Tester { public static void main(String[] args){ int[][] twoDimenArray = new int[2][]; //first row has 3 columns twoDimenArray[0] = new int[3]; //second row has 4 columns twoDimenArray[1] = new int[4]; int counter = 0; //initializing array for(int row=0; row < twoDimenArray.length; row++){ for(int col=0; col < twoDimenArray[row].length; col++){ twoDimenArray[row][col] = counter++; } } //printing array for(int row=0; row < twoDimenArray.length; row++){ System.out.println(); for(int col=0; col < twoDimenArray[row].length; col++){ System.out.print(twoDimenArray[row][col] + " "); } } } }
Output
0 1 2 3 4 5 6
- Related Articles
- Jagged Array in C#
- How to access elements from jagged array in C#?
- What are the differences between a multi-dimensional array and jagged array?
- How to add items/elements to an existing jagged array in C#?
- What is the type of elements of the jagged array in C#?
- How to use use an array of pointers (Jagged) in C/C++?
- What are jagged arrays and explain with an example in Java?
- How to find the length and rank of a jagged array in C#?
- How to find the length of jagged array using a property?
- What are jagged arrays in C#?
- How to define jagged arrays in C#?
- How to initialize jagged arrays in C#?
- How do you initialize jagged arrays in C#?
- How do you access jagged arrays in C#?
- How do you declare jagged arrays in C#

Advertisements