1.

Differentiate between Array and ArrayList in Java.

Answer»

Following are the differences between Arrays and ArrayLists in Java :

  • Java provides arrays as a fundamental functionality. ArrayList is a component of Java's collection system. As a RESULT, It is used to ACCESS array members, while ArrayList provides a set of methods for accessing and modifying components.
  • ArrayList is not a fixed-size data structure, but Array is. When creating an ArrayList OBJECT, there is no need to provide its size. Even if we set a maximum CAPACITY, we can add more parts afterward.
  • Arrays can include both primitive data types and class objects, depending on the array's definition. ArrayList, on the other hand, only accepts object entries and not primitive data types. Note that when we use arraylist.add(1);, the primitive int data type is converted to an Integer object.
  • Members of ArrayList are always referencing to objects at various memory locations since ArrayList can't be constructed for primitive data types  As a result, the actual objects in an ArrayList are never kept in the same place. The references to the REAL items are maintained in close proximity. Whether an array is primitive or an object depends on the type of the array. Actual values for primitive kinds are continuous regions, whereas allocation for objects is equivalent to ArrayList.
  • Many other operations, such as indexOf() and delete(), are supported by Java ArrayList. Arrays do not support these functions.


Discussion

No Comment Found