How to remove the last element from an ArrayList in Java

1 Answer

0 votes
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        ArrayList<String> arr = new ArrayList<>(Arrays.asList("C#", "Java", "C", "C++"));
        
        arr.remove(arr.size() - 1);
        
        System.out.println(String.join(", ", arr));
    }
}

   
/*
run:
   
C#, Java, C
   
*/

 



answered Aug 21, 2024 by avibootz

Related questions

2 answers 154 views
4 answers 467 views
1 answer 178 views
1 answer 188 views
1 answer 259 views
1 answer 177 views
...