Posts

Showing posts from June, 2017

Java multidimensional array

Image
In Java , a multidimensional array data is stored in row and column based index. In the Java programming language, a multidimensional array is an array whose components are themselves arrays.  Example :         class TwoDArrayDemo{             public static void main(String args[]){                 //declaring and initializing 2D array                  int arr[][] ={{5,10},{15,20}};               //printing 2D array               for(int i=0;i<2;i++){   // Row                      for(int j=0;j<2;j++){   // Column                             System.out.print("["+i+"]["+j+"] : "+ arr[i][j] +"   ");                             }                       System.out.println();            }        }    }  Output :                 [0][0] : 5    [0][1] : 10                 [1][0] : 15  [1][1] : 20 Find us :         Facebook : @apnaandroid         Google+   : Apna Java         Youtube : Android & Java Tu

Java Arrays

Image
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. Each item in an array is called an element , and each element is accessed by its numerical index . Types Of Array : Single Dimensional Array Multidimensional Array Array Declaring :    int[] anArray ; Creating an Array :     anArray = new int[10];  // new is an operator to create memory   Initializing an Array : // initialize first element     anArray[0] = 10; // initialize second element   anArray[1] = 15; ... ... // and last element   anArray[9] = 200;   Accessing an Array : System.out.println(" Element 1 at index 0: " + anArray[0] );   Output :    Element 1 at index 0 : 10   Example :     class ArrayDemo{       public static void main(String args[]){             //Another way we can declaring, creating and initializing an array