1ArrayList<Integer> list = new ArrayList<>();
2list.add(1);
3list.add(2);
4list.add(3);
5
6list.remove(list.size()-1); //removes 3
1// How to remove last element from arraylist in java
2import java.util.ArrayList;
3import java.util.List;
4public class ArrayListRemoveLastElement
5{
6 public static void main(String[] args)
7 {
8 List<Integer> al = new ArrayList<>();
9 al.add(56);
10 al.add(28);
11 al.add(39);
12 al.add(59);
13 al.add(82);
14 // using size() method to find index of last element
15 int index = al.size() - 1;
16 // deleting last element by passing index
17 al.remove(index);
18 System.out.println("After remove last element from arraylist: " + al);
19 }
20}