91-9990449935 0120-4256464 |
Java ArrayNormally, array is a collection of similar type of elements that have contiguous memory location. Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a java array. Array in java is index based, first element of the array is stored at 0 index. Advantage of Java Array
Disadvantage of Java Array
Types of Array in javaThere are two types of array.
Single Dimensional Array in javaSyntax to Declare an Array in javaInstantiation of an Array in javaExample of single dimensional java arrayLet's see the simple example of java array, where we are going to declare, instantiate, initialize and traverse an array. Test it NowOutput: 10 20 70 40 50 Declaration, Instantiation and Initialization of Java ArrayWe can declare, instantiate and initialize the java array together by: Let's see the simple example to print this array. Test it NowOutput:33 3 4 5 Passing Array to method in javaWe can pass the java array to method so that we can reuse the same logic on any array. Let's see the simple example to get minimum number of an array using method. Test it NowOutput:3 Multidimensional array in javaIn such case, data is stored in row and column based index (also known as matrix form). Syntax to Declare Multidimensional Array in javaExample to instantiate Multidimensional Array in javaExample to initialize Multidimensional Array in javaExample of Multidimensional java arrayLet's see the simple example to declare, instantiate, initialize and print the 2Dimensional array. Test it NowOutput:1 2 3 2 4 5 4 4 5 What is the class name of java array?In java, array is an object. For array object, an proxy class is created whose name can be obtained by getClass().getName() method on the object. Test it NowOutput:I Copying a java arrayWe can copy an array to another by the arraycopy method of System class. Syntax of arraycopy methodExample of arraycopy methodTest it NowOutput:caffein Addition of 2 matrices in javaLet's see a simple example that adds two matrices. Test it NowOutput:2 6 8 6 8 10
Next TopicWrapper class in Java
|