How To Create ArrayList In Java

 

How To Create ArrayList In Java

In this program we make a arraylist and add element in it.Here
ArrayList<String>  arr = new ArrayList<String>();
String tell that arraylist arr store string type elements.

import java.util.ArrayList;

public class CreateArrayList {

public static void main(String[] args) {
ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
arr.add(“c”);
arr.add(“php”);
arr.add(“html”);
arr.add(“java”);
// print arraylist
System.out.println(“arrayList is = ” + arr);
}

}

Output:
 arrayList is = [c, php, html, java]
 

Notice: compact(): Undefined variable: limits in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: groupby in /home/javaprof/public_html/wp-includes/class-wp-comment-query.php on line 853

Leave a Reply

Your email address will not be published. Required fields are marked *

84 + = 93