Example usage for java.util List add

List of usage examples for java.util List add

Introduction

In this page you can find the example usage for java.util List add.

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:Main.java

public static void main(String[] args) {

    List<String> carList = new ArrayList<String>();

    carList.add("A");
    carList.add("B");
    carList.add("C");
    carList.add("D");

    String[] carArray = carList.toArray(new String[0]);

    for (String car : carArray) {
        System.out.println(car);/*w  ww  . j a v a2 s  . c  o  m*/
    }
}

From source file:Student.java

public static void main(String[] args) {
    List<Student> al = new ArrayList<>();
    al.add(new Student("Z", 34.34));
    al.add(new Student("M", 123.22));
    al.add(new Student("A", 1378.00));
    al.add(new Student("D", 99.22));
    al.add(new Student("Q", -19.08));
    Collections.sort(al);/*w w  w .j ava 2  s  .  c  o m*/
    System.out.println(al);
}

From source file:Main.java

public static void main(String[] argv) {
    List<String> arrayList1 = new ArrayList<String>();

    arrayList1.add("A");
    arrayList1.add("A");
    arrayList1.add("B");
    arrayList1.add("B");
    arrayList1.add("B");
    arrayList1.add("C");

    HashSet<String> hashSet = new HashSet<String>(arrayList1);

    List<String> arrayList2 = new ArrayList<String>(hashSet);

    for (Object item : arrayList2)
        System.out.println(item);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new LinkedList<String>();

    list.add("a");
    list.add("b");
    list.add("c");
    list.add("d");
    list.add("e");
    list.add("f");

    Collections.sort(list);/*w ww.  jav a  2s. c om*/
    System.out.println(list);
    int index = Collections.binarySearch(list, "c");
    if (index > 0) {
        System.out.println("Found at index = " + index);
        String month = (String) list.get(index);
        System.out.println(month);
    }
}

From source file:MyComparator.java

public static void main(String args[]) {
    List<String> ts = new ArrayList<String>();

    ts.add("tutorial");
    ts.add("from");
    ts.add("java2s.com");

    Collections.sort(ts);/* w  w  w  .  ja v  a2s. co  m*/
    for (String element : ts) {
        System.out.println(element + " ");
    }
    System.out.println();
    Collections.sort(ts, new MyComparator());
    for (String element : ts) {
        System.out.println(element + " ");
    }

}

From source file:Main.java

public static void main(String[] args) {
    Map<Integer, String> grades = new HashMap<Integer, String>();

    grades.put(1, "A");
    grades.put(2, "B");
    grades.put(3, "C");
    grades.put(4, "D");
    grades.put(5, "E");

    String value = grades.get(1);

    List<String> dayNames = new ArrayList<String>();
    dayNames.add("Sunday");
    dayNames.add("Monday");
    dayNames.add("Tuesday");
    dayNames.add("Wednesday");

    String firstDay = dayNames.get(0);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    list.add("Java");
    list.add("Oracle");
    list.add("CSS");
    list.add("XML");

    System.out.println("List: " + list);

    int count = list.size();
    System.out.println("Size of  List: " + count);

    // Print each element with its index
    for (int i = 0; i < count; i++) {
        String element = list.get(i);
        System.out.println("Index=" + i + ", Element=" + element);
    }/* ww w  .ja v a  2  s  .  co  m*/

    List<String> subList = list.subList(1, 3);
    System.out.println(subList);

    // Remove "CSS" from the list 
    list.remove("CSS"); // Same as list.remove(2);
    System.out.println(list);
}

From source file:Main.java

public static void main(String args[]) {
    List<String> list = new ArrayList<String>();

    list.add("A");
    list.add("B");
    list.add("C");
    list.add("C");
    list.add("C");
    list.add("C");
    list.add("C");

    for (String s : list) {
        if (s.equals("B")) {
            list.remove("B");
        }/*from ww  w.ja  v  a 2 s  .  c o m*/
        System.out.println(s);
    }
}

From source file:ProcessBuilderDemo.java

public static void main(String argv[]) throws InterruptedException, IOException {

    List<String> command = new ArrayList<String>();
    command.add("notepad");
    command.add("foo.txt");
    ProcessBuilder builder = new ProcessBuilder(command);
    Map<String, String> environ = builder.environment();
    environ.put("PATH", "/windows;/windows/system32;/winnt");
    builder.directory(new File(System.getProperty("user.home")));

    final Process godot = builder.start();

    godot.waitFor();//from  w  w  w  .j  av  a2s  .  co  m

    System.out.println("Program terminated!");
    return;
}

From source file:com.croer.javaaccess.ItemBusqTest.java

public static void main(String[] args) {
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
            "C:\\Users\\IBM_ADMIN\\Documents\\@Projects_Eli\\201309 Finder&Getter\\_NBP\\digitalcatalog\\JavaAccess\\src\\main\\java\\springXMLConfig.xml");
    ItembusqManagement bean3 = context.getBean("itembusqManagement", ItembusqManagement.class);
    OrtogramaRepository ortoRepo = context.getBean("ortogramaRepository", OrtogramaRepository.class);
    ItembusqRepository itemRepo = context.getBean("itembusqRepository", ItembusqRepository.class);

    Ortograma ortoTmp = ortoRepo.findOne("vaca");
    List<Ortograma> ortoList = new ArrayList<>();
    ortoList.add(ortoTmp);
    Itembusq itembusq = itemRepo.findOne(new ItembusqPK("Producto", "99"));
    bean3.borraOrtograma(ortoList, itembusq);
}