How to Remove an Element from Collection using Iterator Object in Java? Last Updated : 07 Jan, 2021 Comments Improve Suggest changes Like Article Like Report Collection in Java is a set of interfaces like List, Set, and Queue. An iterator in Java is used to iterate or traverse through the elements of the Collection. There are three types of iterator in Java namely, Enumerator, Iterator, and ListIterator. The two ways of removing an element from Collections using Iterator : Using IteratorUsing ListIterator Approach 1: Using Iterator A List is created and elements are added to the list using the add() method.The Iterator object is used to iterate over the elements of the list using the hasNext() and next() methods.An if the condition is used within the while loop and when the condition is satisfied, the particular element is removed using the remove() method.When the entire list is traversed again the element which was removed is no longer present in the list. Java // Java program to Remove an Element from // Collection using Iterator import java.util.ArrayList; import java.util.Iterator; class IteratorDemo { public static void main(String[] args) { ArrayList<Integer> l = new ArrayList<Integer>(); for(int i=0;i<=50;i=i+5) { l.add(i); } Iterator<Integer> itr = l.iterator(); System.out.println("List before removal"); for(int i=0;i<l.size();i++) { System.out.print(l.get(i)+" "); } while(itr.hasNext()) { if(itr.next()%2==1) itr.remove(); } System.out.println("\nList after removal"); for(int i=0;i<l.size();i++) { System.out.print(l.get(i)+" "); } } } OutputList before removal 0 5 10 15 20 25 30 35 40 45 50 List after removal 0 10 20 30 40 50 Approach 2: Using ListIterator A list is created and elements are added to the list using the add() method.The ListIterator object is used to iterate over the elements of the list using the hasNext() and next() methods.An if condition is used within the while loop and when the condition is satisfied, the particular element is removed using the remove() method.When the entire list is traversed again the element which was removed is no longer present in the list. Java // Java program to Remove an Element from // Collection using ListIterator import java.util.ArrayList; import java.util.ListIterator; public class ListIteratorDemo { public static void main(String[] args) { ArrayList<String> l = new ArrayList<String>(); l.add("January"); l.add("February"); l.add("March"); l.add("April"); l.add("May"); l.add("June"); l.add("July"); l.add("August"); ListIterator<String> itr = l.listIterator(); System.out.println("List before removal"); for (int i = 0; i < l.size(); i++) System.out.print(l.get(i) + " "); while (itr.hasNext()) { if (itr.next().equals("March")) { itr.remove(); } } System.out.println("\nList after removal"); for (int i = 0; i < l.size(); i++) System.out.print(l.get(i) + " "); } } OutputList before removal January February March April May June July August List after removal January February April May June July August Comment More infoAdvertise with us Next Article How to Remove an Element from Collection using Iterator Object in Java? S Shreyasi_Chakraborty Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Collections Java-Iterator +2 More Practice Tags : JavaJava-Collections Similar Reads Java Program to Remove an Element from ArrayList using ListIterator ListIterator.remove() method removes the last element from the list that was returned by next() or previous() cursor positions. It can be called only once per call to next or previous. It can be made only if the operation â add(E) has not called after the last call to next or previous. Internal work 4 min read Java Program to Remove a Specific Element From a Collection remove() method is used to remove elements from a collection. It removes the element at the specified position in this list. Shifts any subsequent elements to the left by subtracts one from their indices. In simpler words, the remove() method is used for removing the element from a specific index fr 3 min read How to Remove Elements from a LinkedHashMap in Java? A LinkedHashMap is a part of the Collection Framework from java.util package Java and is similar to a HashMap, except that a LinkedHashMap preserves the insertion order among the keys/entries. In this article, we will look at how to remove the elements from a LinkedHashMap in Java. Program to Remove 2 min read Removing last element from ArrayList in Java Given an ArrayList collection in Java, the task is to remove the last element from the ArrayList. Example: Input: ArrayList[] = [10, 20, 30, 1, 2] Output: [10, 20, 30, 1] After removing the last element 2, the ArrayList is: [10, 20, 30, 1] Input: ArrayList[] = [1, 1, 2, 2, 3] Output: [1, 1, 2, 2] Af 2 min read How to Delete User Defined Objects from LinkedHashSet? The LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements. When the iteration order is needed to be maintained this class is used. When iterating through a HashSet the order is unpredictable, while a LinkedHashSet lets us iterate through the elements 2 min read Like