21 January, 2015

Java - The ArrayList Class

This post highlight's some of the important points about ArrayList.


  • ArrayList class extends AbstractList and implements List interface
  • Data structure used for ArrayList is resizable or growable arrays
  • Duplicates are allowed in ArrayList
  • Insertion order is preserved
  • Heterogeneous objects can be inserted.
  • Null values are allowed
  • ArrayList is serializable
  • ArrayList is clonable


Now Lets try to perform some basic operation and learn more about ArrayList.

Exercise 1:  Create a ArrayList object

Array List has 3 constructors.


Exercise 2: Add 3 integers to ArrayList and check the size of the

Note: ArrayList her uses Generics, which is specifying what type of a object we are inserting in.

Exercise 3: Print the contents of a array using iterator


Exercise 4 : Remove element 2 from the list and print the list

Exercise 5: Create another list from l1


Exercise 6: check if 1 is a part of the list
 

Exercise 7: insert null and print the list






Hope this would give you a good head start with ArrayList.