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 165 views
4 answers 487 views
1 answer 184 views
1 answer 198 views
1 answer 269 views
1 answer 186 views
...