The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to Declare and Initialize Multi-dimensional (2D and 3D) Array in Java with Example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to Declare and Initialize Multi-dimensional (2D and 3D) Array in Java with Example Posted: Oct 15, 2014 7:50 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to Declare and Initialize Multi-dimensional (2D and 3D) Array in Java with Example
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
An array of more than one dimension is known as multi-dimensional array. Two of the most common examples of multi-dimensional arrays are two and three dimensional array, known as 2D and 3D array, anything above is rare. I have never seen 4 dimensional arrays, even 3D arrays are not that common. Now question comes, when do use multi-dimensional array? Any real life example? Well, 2D arrays are very common on platform games like Super Mario Bros to represent screen or terrain; 2D arrays can also be used to represent structures like spreadsheet, or to draw board games like Chess, which requires 8x8 board, Checkers and  Tic-Tac-Toe, which requires 3 rows and 3 columns. Another popular application of multi-dimensional arrays are in matrix manipulation. For example to represent a 3x3 matrix you need a two dimensional array of 3 one dimensional array each containing 3 elements. Similarly to represent 3x2 matrices you need 2 two dimensional array of one dimensional array of length 3. In other words, each row in two dimensional array is a one dimensional array.  Java truly doesn't support multi-dimensional array but allows you to create and use array of any number of dimensional. Two dimensional array is actually an array of one dimensional array. This is unlike languages like C or FORTRAN, which allows Java array to have rows of varying length i.e. a multidimensional array can have 2 columns in one row and 3 columns in second. Similar to one dimensional array, length of two dimensional array is also fixed. You can not change length of any array, i.e. number of rows and columns will remain fixed. A 2x2 array can hold total 4 elements and they can be accessed using row and column index e.g. a[0][0] will give you elements in first row and first column, similarly a[1][1] will give you elements from 2nd row and 2nd column. Just like normal array, index start at 0 and finishes at length -1.
Read more »

Read: How to Declare and Initialize Multi-dimensional (2D and 3D) Array in Java with Example

Topic: java.sql.BatchUpdateException – How to resolve Batch Update Exception Previous Topic   Next Topic Topic: WildFly subsystem for RHQ Metrics

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use