Tutorials

Java 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 : 126
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!