how add some elemnts to list 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: insert data into list java
List<String> list = new ArrayList<String>();
list.add(s1);
list.add(s3);
list.add(1, s2);
System.out.println(list);