Check out example codes for "java arraylist". It will help you in understanding the concepts better.

Code Example 1

import java.util.List; //list abstract class
import java.util.ArrayList; //arraylist class

//Object Lists
List l = new ArrayList();
ArrayList a = new ArrayList();

//Specialized List
List<String> l = new ArrayList<String>();
ArrayList<Integer> a = new ArrayList<Integer>();
//only reference data types allowed in brackets <>

//Initial Capacity
List<Double> l = new ArrayList<Double>(5);
//list will start with a capacity of 5
//saves allocation times

Code Example 2

// Java program to change elements 
// in an ArrayList 
  
import java.util.*; 
  
public class GFG { 
  
    public static void main(String args[]) 
    { 
        ArrayList<String> al = new ArrayList<>(); 
  
        al.add("Geeks"); 
        al.add("Geeks"); 
        al.add(1, "Geeks"); 
  
        System.out.println("Initial ArrayList " + al); 
  
        al.set(1, "For"); 
  
        System.out.println("Updated ArrayList " + al); 
    } 
}

Code Example 3

import java.util.ArrayList; // import the ArrayList class

ArrayList<String> cars = new ArrayList<String>(); // Create an ArrayList object

Code Example 4

import java.util.ArrayList;
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(0);
myList.remove(0);//Remove at index 0
myList.size();
myList.get(0);//Return element at index 0

Code Example 5

ArrayList<String> a = new ArrayList<>( Arrays.asList(oldArray));

Code Example 6

import java.util.ArrayList;

Learn ReactJs, React Native from akashmittal.com