Android Projects

Android Development Books


Multidimensional array in java with android

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. You've seen an example of arrays already, in the main method of the "Hello World!" application. This section discusses arrays in greater detail.

Illustration of an array as 10 boxes numbered 0 through 9; an index of 0 indicates the first element in the array
An array of ten elements
Each item in an array is called an element, and each element is accessed by its numerical index. As shown in the above illustration, numbering begins with 0. The 9th element, for example, would therefore be accessed at index 8.

public class MultiArray {
  // Declare constants
  final static int ROWS = 10;

  final static int COLS = 5;

  public static void main(String[] args) {

    // Local varaibles
    int rowCount;
    int colCount;
    int totalSize;

    // Declare and allocate an array of bytes
    byte[][] screenPix = new byte[ROWS][COLS];

    // Obtain and store array dimensions
    rowCount = screenPix.length;
    colCount = screenPix[COLS].length;
    totalSize = rowCount * colCount;

    // To obtain the total number of elements of a
    // two-dimensional ragged array you need to get the size of
    // each array dimension separately

    // Display array dimensions
    System.out.println("Array row size:    " + rowCount);
    System.out.println("Array column size: " + colCount);
    System.out.println("Total size:        " + totalSize);

     // First allocate the rows of an array
    byte[][] raggedArray = new byte[5][];

    // Now allocate the columns
    raggedArray[0new byte[2];
    raggedArray[1new byte[2];
    raggedArray[2new byte[4];
    raggedArray[3new byte[8];
    raggedArray[4new byte[3];

    //     static array initialization
    byte[][] smallArray = { { 10111213 }20212223 },
        30313233 }40414243 }};

    // Display the array element at row 2, column 3
    System.out.println(smallArray[1][2])// Value is 21
 for more problem to see click here.

Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...


Thanks for your comment

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

Related Posts Plugin for WordPress, Blogger...
© Google Android Lovers
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0