Posts

Showing posts with the label length vs length()

Arrays in Java

Image
What are Java Array? Array is an Indexed Collection of Fixed Number of Homogeneous/Similar Data Elements . int[ ] x = new int[5]; Example: Valid   Array Examples: int[ ] arr1=new int[5]; int arr2[ ]=new int[5]; int [ ]arr3=new int[5]; int[ ] arr4 = new int[ ]{10,20,30,40,50}; int[ ] arr5 = {10,20,30,40,50}; Arrays can be initialized when they are declared. The array will automatically be created large enough to hold the number of elements you specify in the array initializer. There is  no  need to use  new . public static void main(String args[]) {    int month_days[ ];     month_days = new int[12];     month_days[0] = 31;     month_days[1] = 28;     month_days[2] = 31;     month_days[3] = 30;     month_days[4] = 31;     mon...