The length of an array can be obtained using the property of length whereas ArrayList does not support length property, but we can use size() method to get the number of objects in the list.
Finding the length of the array
- Int [] array = new int[4];
- System.out.println("The size of the array is " + array.length);
-
Finding the size of the ArrayList
- ArrayList<String> list=new ArrayList<String>();
- list.add("ankit");
- list.add("nippun");
- System.out.println(list.size());
-