access 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: java list of objects example
List<Object> listAnything = new ArrayList<Object>();
List<String> listWords = new ArrayList<String>();
List<Integer> listNumbers = new ArrayList<Integer>();
List<String> linkedWords = new LinkedList<String>();