See More

package JavaSessions; public class ArrayConcept { public static void main(String[] args) { //array: //1. static array: size is fixed //limitations of static array: //a. size is fixed(static): extra memory and less memory //b. can not store diff types of data //to overcome for both the limitations: we have to use dynamic array: Collections-> ArrayList //2. dynamic array: dynamic sized //int array: int i[] = new int[4]; i[0] = 10; i[1] = 20; i[2] = 30; i[3] = 40; //i[4] = 50;//ArrayIndexOutOfBoundsException //i[-1] = 60;//ArrayIndexOutOfBoundsException System.out.println(i); System.out.println("Li = " + 0); System.out.println("length =" + i.length); int l = i.length;//4 System.out.println("Hi = " + (l-1));//3 System.out.println(i[0]); System.out.println(i[3]); //System.out.println(i[4]);//ArrayIndexOutOfBoundsException - RunTime //System.out.println(i[-1]);//ArrayIndexOutOfBoundsException - RunTime System.out.println("------typical for loop---------"); //to print all the values from array: for loop: for(int k=0; k