Java List add and insert by position

Description

Java List add and insert by position


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

public class Main{
  public static void main(String args[]) throws Exception {
    // Create/fill collection
    List<String> list = new ArrayList<>();
    list.add("A");
    list.add("B");
    list.add("C");
    System.out.println(list);/* w w w . ja  va 2  s.c o m*/

    list.add("HTML");
    list.add("Binary");
    list.add("C++");
    list.add(1, "demo2s.com");

    System.out.println(list);

  }
}



PreviousNext

Related