Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- //Java ArrayList Remove
- import java.util.ArrayList;
- public class JavaArrayListRemove {
- public static void main(String args[]){
- //create new ArrayList
- ArrayList<String> aListColors = new ArrayList<String>();
- aListColors.add("Red");
- aListColors.add("Green");
- aListColors.add("Blue");
- //Java ArrayList Remove
- /*
- * To remove single element from ArrayList, use
- * Object remove(int index) method.
- *
- * This method returns object that has been removed from
- * ArrayList object.
- */
- //this will remove green from ArrayList
- aListColors.remove(1);
- /*
- * OR
- * remove the element from ArrayList by passing the element itself
- * instead of index using
- * Object remove(Object object) method.
- */
- //this will remove Blue from ArrayList
- aListColors.remove("Blue");
- System.out.println(aListColors);
- }
- }

Post new comment