Arrays in Java

  • An Arrays is a container object that store multiple value of the same type in one variable.
  • Arrays is an object because we are using new operator to create the Array.
  • In Arrays, variable can hold only one value. That value can varying from one statement to another.
  • Array size can be zero, negative or positive value.
  • When the array value will be negative(-ve) then it will be give runtime error.
  • We can declare byte, short type array value.
  • Array declaration should be same as array definition type.
  • Array size will be start from 0 to size-1.
  • In Array every index get default value according to data type.
  • We must provide the array size when create the object of array

              Arrays object creation :-    int[] x=new int[];

					public class ArrayDeclare {
	public static void main(String[] args) {
		// integer array with size 2,index will be 0,1
		int x[] = new int[2];
		// default size iz zero
		System.out.println("default size print :- " + x[0]);
		x[0] = 10;
		x[1] = 20;
		System.out.println("array first value :- " + x[0]);
		System.out.println("array second value :- " + x[1]);

Output :-
default size print :- 0
array first value :- 10
array second value :- 20