Tutorials

Collection Programs


Arraylist Add Items


In this chapter, our task is:

  • we will create an arraylist
  • We will add few elements in arraylist.
  • Print the list

See the code snippet given below.


//Add elements to arraylist
package tihArrayList;

import java.util.ArrayList;
import java.util.List;

public class SimpleArrayList {

      public static void main(String[] args) {

            //create Array List
            List tihList = new ArrayList();

            //Add elements to ArrayList
            tihList.add("Java");
            tihList.add("Spring");
            tihList.add("Hibernate");
            tihList.add("EJB");

            System.out.println(tihList);

      }

}

OUTPUT

[Java, Spring, Hibernate, EJB]

 

 

 



Please Share this page
Views : 62