Get Sublist from ArrayList

This is the program to Get Sublist from ArrayList

—ArrayListSubList.java—

 

OUTPUT

sublist

Add Elements in ArrayList java

—ArrayListAdd.java—

OUTPUT

add element in arraylist

Add ArrayList in ArrayList java

ArrayList can be added in 2 ways into an ArrayList.

 

—ArrayListInArrayList.java—

NOTE: Here two arraylist are created then al1 is added into al

OUTPUT:

arraylist in arraylist

—ArrayListInArrayList1.java—

NOTE: Here first arraylist is created and added to al1 then elements are added to the al1

 OUTPUT:

arraylist in arraylist1

Methods in ArrayList in Java

There are many methods in ArrayList you can get summary from here

Some are describe below
 
—MethodsInArrayList.java—

 

OUTPUT:

methods in arraylist

Difference between Iterator and ListIterator in Java

This post shows the Difference between Iterator and ListIterator in Java through example

Iterator: can traverse only in forward direction

ListIterator: can traverse in forward as well as backward direction

  • It is an interface which provide the capability to traverse the list in both direction.
  • This interface also provide the facility to insert the element in a list that means we can perform removal as well as insertion.
  • Since List is ordered and it is indexed so we can travel it forward direction as well as backward direction , on the other hand Set is unordered that is why the listIterator() method is available only for List interface not for Set.

 

OUTPUT:
difference between iterator and listiterator