ListIterator : add()

The add() method is used to add objects to a collection. This method always takes an object as an argument. If we wish to store primitive data type values, we have to convert them into objects and then add them to the collection.

Program

0

 

 

 

Program Source

import java.util.ArrayList;
import java.util.ListIterator;

public class Javaapp {

    public static void main(String[] args) {
        
        ArrayList array1 = new ArrayList();
        array1.add(30);
        array1.add(40);
        array1.add(50);
        array1.add(60);
        System.out.println("array1 : "+array1);
        
        ListIterator itr = array1.listIterator();
        itr.add(10);
        itr.add(20);
        System.out.println("array1 : "+array1);
    }
}

Leave a Comment