how to add in list in java 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");
vowels.add("E");
vowels.add("U");
System.out.println(vowels);
vowels.add(2, "I");
vowels.add(3, "O");
System.out.println(vowels);
}
}
Example 2: java add a list to a list
List mylist.addAll(secondList);
Example 3: how to add a list in a list java
List<SomePojo> list = new ArrayList<SomePojo>();
List<SomePojo> anotherList = new ArrayList<SomePojo>();
anotherList.add(list);