0 likes | 15 Views
An array is a group of homogeneous(same type) elements,It will not support heterogeneous(another type) elements.<br>for more free learning visit:<br>https://quipoin.com/view/Java/Overview
E N D
Arrays Arrays in JAVA
Overview • An array is index-based, and the index number starts from 0. • Array generally supports the same type of elements we cannot store different types of elements in the array. • If the array has a fixed size length it will not grow dynamically. • Array doesn't support any standard data structure it always stores elements linearly. • Array doesn't provide any inbuilt algorithms for searching and sorting. • If we don't know the number of elements and type of element we want to store non-linearly then we go for Data-Structures (In Java we call them Collections).
Program public class ArrayDemo1 { public static void main(String[] args) { int[] a1= new int[5]; System.out.println("Size of the array:"+a1.length); a1[0]=10; a1[1]=15; a1[2]=20; a1[3]=25; a1[4]=30; System.out.println("---------------------"); System.out.println("Elements of an array:"); for(int i=0;i<a1.length;i++) { System.out.println(a1[i]); } System.out.println("---------------------"); } }