How to Add an Item in an ArrayList in Java


In this example we will show the method to add an item in an ArrayList in Java.

Source Code

package com.beginner.examples;

import java.util.ArrayList;

public class AddArrayList { 
  public static void main(String[] args) {
    ArrayList strs = new ArrayList();
    strs.add("a"); // add an item
    System.out.println(strs);
  } 
}

Output:

[a]

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments