In this blog we are going to talk about arrays
in java and how to use them. In the first part of this following blog, we will
explain arrays and give a brief introduction of syntax and uses in java and
further move forward to see multi-dimensional array concept and how to use it
in java.
The java is a very robust programming language
and provides use with many better options like array-list and vectors. These
are dynamic implementations of the well-known array data structure. But knowing
the basics of array and its related concept is very important. So knowing this
lets move forward and take a look at the importance of array.
________________________________________________________
Before we go any
further, let's look at why we need Java Array in the first place:
- Arrays are a
common data storage structure.
- Arrays in Java
allow us to store multiple objects of the same type.
- It may be used in
conjunction with a loop to access items by index.
Arrays
Introduction:
Arrays in Java are
objects that represent homogeneous data structures. Arrays are data structures
that contain one or more values of a given data type and allow for indexed
access to those values. An array element's index is used to access it.
Arrays are a useful way to bring together relevant data.
Types of Array in java
One-Dimensional
Arrays :
Syntax :type variable-name[];
OR
type[] variable-name;
Examples
of 1D arrays:
Multidimensional Arrays:
Multidimensional
arrays are collections of arrays, with each array member referring a different
collection of arrays. This form of array is also known as jagged arrays. A
multidimensional array is created by appending one set of square brackets ([])
to each dimension.
This
visual might help in understanding the multi-dimensional
array
and its indexing.
The Syntax for 2D Array is as follows:
OR
type[][] variable-name;
For more detailed explanation regarding the use of syntax check out the following example:
Example
no1:
Example
no2:
How Indexing works in Multi-Dimensional Array?
Let's see how indexing for the 2D array works. It might seem scary at first but once we get a hold of it, it will seem very intuitive and easy.
So to get a good idea let's check out this example:
In the given example we will see how 2D Array treats each of the
array that is contained inside of it. We can even use methods like we use on 1D
Array and calculate the length.
Tabular representation of a two-dimensional array:
A two-dimensional array is a table with 'x' rows and 'y' columns, with row numbers ranging from 0 to (x-1) and column numbers ranging from 0 to (y-1).
Accessing and printing of 2D array:
You already know that
you may assign a value to each of the 2d array's individual elements when you
initialize it. This is accomplished by accessing a specific element using the
array's row and column indexes. You may retrieve the value of an individual
element and print it to the user in the same way that you can initialize it.
Example for printing of 2D Array:
3D Array and its implementation
Now we have already understood what a 2D array actually is, so using the same concept we can create a 3D array. By intuition the 3D array would a array that stores a array of array. Now it may first sound a bit weird but actually its just as simple as a 2D array. Now, lets take a visual look at what we discussed earlier regarding the 3D array.
Now that let's take a look at the coding example on how to declare a 3D array:
Now we will look at an example on how to print and access the the elements in the 3D array:
Conclusion:
In conclusion we would to say that array is a
very important data structure and is a very
important part of java programming
language. Java has many advanced implementations of the static arrays we learned now namely like array-list
and vectors which have similar concepts as that of static single and
multidimensional array. That tells us that array even though is a simple
structure but is very effective and useful. The concept of multidimensional
array is very simple and intuitive if we could visualize it.

Informative...
ReplyDeleteTrue hai
DeleteTeach us also how to make blogs
ReplyDeleteHelpful
ReplyDeletereally helpful
ReplyDeleteGreat oneπ☺️
ReplyDeleteNice Blog
ReplyDeleteGreat blog
ReplyDeleteVery Informative
Muddo bhai...kab aara phir aapka blog ? π
DeleteNice ππ
ReplyDeleteFound helpfull.....
ReplyDeleteGot many things to learn from this blog.
Informative
ReplyDeleteGreat work
ππpranam tompr
Delete@Unknown ++
DeleteThis comment has been removed by the author.
ReplyDeletehttps://grabify.link/SZ1KW6
DeletePlz suppot me π€§
Great work mate
ReplyDeleteVery informative
Noice
ReplyDeleteNice work
ReplyDeleteVery informative
We know π
Deletenicely explained
ReplyDeleteInformative
ReplyDeleteGood work
Nice
ReplyDeleteVery informative π
ReplyDeleteReally Informative !!!
ReplyDeleteAmazing!!!
ReplyDeleteVery informative....Keep it upπ
ReplyDeleteReally helpful ,was very informative.
ReplyDeleteCleared mine whole Concept... Awesome...
ReplyDeletevery well written blog
ReplyDeleteNice, keep it up vro.
ReplyDeletehttps://grabify.link/SZ1KW6
DeletePlz suppot me π€§ paste this link in your browser to show your suppot π
Palan hardy...themks for your appreciation π pranam
ReplyDeleteKeep up this Good Work, really very informative blog. Looking forward for More such information blog
ReplyDeleteVery helpful and informative .
ReplyDelete