Go Back

Example of single dimensional java array

7/27/2021
All Articles

#Array_in_Java #array #java_array

Example of single dimensional java array

Example of single dimensional java array

Array in Java:

Normally, array is a collection of similar type of elements that have contiguous memory location.

In 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 elements in an array.  Array is index based.

 

Let's see the simple example of java array, where we are going to declare, instantiate, initialize and traverse an array.


class B{  

	public static void main(String args[]){  
  
	int a[]=new int[5];//declaration and instantiation  
	a[0]=10;//initialization  
	a[1]=20;  
	a[2]=70;  
	a[3]=40;  
	a[4]=50;  

	for(int i=0 ;i < a.length;i++) 
		System.out.println(a[i]);  
  
		}
}  



Conclusion of our topic java array

Here we learn how to implement Example of single dimensional java array.

Creating one dimensional array and run code using java command line .

Hope you like it subscribe our instagram and facebook account for more update.

Article