wesley Posted September 2, 2016 Share Posted September 2, 2016 Hello, I have java code. The code add and remove data from the arraylist. My question is: how can I show the deleted item from the arraylist in system.out.println? thanks in advance. my code is: public static void main(String[] args) { // TODO code application logic here ArrayList<String>items = new ArrayList<>(); items.add("oval"); items.add("polygon"); items.add("spline"); items.add("PaintedText"); items.add("image"); System.out.println("Size of list: " + items.size()); // let us print all the elements available in list for (String number : items) { System.out.println(number); } // Removes element at 3rd position items.remove(2); System.out.println( items.size()); // let us print all the elements available in list for (String number : items) { System.out.println(number); } } Link to comment Share on other sites More sharing options...
justsomeguy Posted September 2, 2016 Share Posted September 2, 2016 You need to save the item in another variable before removing it from the array. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now