add element to arraylist java code example
Example 1: how to add elements to Jlist
DefaultListModel<String> model = new DefaultListModel<>();
JList<String> list = new JList<>( model );
for ( int i = 0; i < customers.length; i++ ){
model.addElement( customers[i].getName() );
}
Example 2: java insert into arraylist
ArrayList<Integer> str=new ArrayList<Integer>();
str.add(0);
str.add(1);
str.add(1, 11);
Example 3: insert element into arraylist java
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("foo");
arrayList.add("bar");
arrayList.add(1, "baz");
Example 4: java add a list to a list
List mylist.addAll(secondList);
Example 5: how to add to an arraylist java
import java.util.ArrayList;
public class Details {
public static void main(String[] args) {
ArrayList<String> al= new ArrayList<String>();
al.add("Ram");
al.add("Shyam");
al.add("CPS");
al.add("John");
al.add("Steve");
System.out.println("Elements of ArrayList of String Type: "+al);
Example 6: java arraylist add
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("item");
System.out.println(arrayList.contains("item"));
arrayList.remove("item");