java add to list code example

Example 1: java append to list

package com.journaldev.examples;

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

public class ListAddExamples {

	public static void main(String[] args) {

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

		vowels.add("A"); // [A]
		vowels.add("E"); // [A, E]
		vowels.add("U"); // [A, E, U]

		System.out.println(vowels); // [A, E, U]

		vowels.add(2, "I"); // [A, E, I, U]
		vowels.add(3, "O"); // [A, E, I, O, U]

		System.out.println(vowels); // [A, E, I, O, U]
	}
}

Example 2: list in java

LIST: Can store duplicate values,
      Keeps the insertion order. 
      It allows multiple null values, 
      Also we can read a certain value by index.
- ArrayList not syncronized, array based class 
- LinkedList not synchronized, doubly linked
- Vector is synchronized, thread safe

Example 3: java add a list to a list

List mylist.addAll(secondList);

Example 4: how to add a list in a list java

List<SomePojo> list = new ArrayList<SomePojo>();

List<SomePojo> anotherList = new ArrayList<SomePojo>();
anotherList.add(list);