- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to remove an element from List with ListIterator
Let’s say the following is our List with elements −
ArrayList < String > arrList = new ArrayList < String > (); arrList.add("Jack"); arrList.add("Tom"); arrList.add("Brad"); arrList.add("Amy"); arrList.add("Ben"); arrList.add("Peter"); arrList.add("Katie"); arrList.add("Tim");
Now, use the listIterator(). The next() method returns the next element in the List. Hoverer,remove an element using remove() method −
ListIterator<String>iterator = arrList.listIterator(); iterator.next(); iterator.remove();
Example
import java.util.ArrayList; import java.util.ListIterator; public class Demo { public static void main(String[] args) { ArrayList<String>arrList = new ArrayList<String>(); arrList.add("Jack"); arrList.add("Tom"); arrList.add("Brad"); arrList.add("Amy"); arrList.add("Ben"); arrList.add("Peter"); arrList.add("Katie"); arrList.add("Tim"); System.out.println("List..."); for (String str: arrList) { System.out.println(str); } ListIterator<String>iterator = arrList.listIterator(); iterator.next(); iterator.remove(); System.out.println("Updated List..."); for (String str: arrList) { System.out.println(str); } } }
Output
List... Jack Tom Brad Amy Ben Peter Katie Tim Updated List... Tom Brad Amy Ben Peter Katie Tim
- Related Articles
- Remove an element from an ArrayList using the ListIterator in Java
- Replace an element from a Java List using ListIterator
- Insert an element to List using ListIterator in Java
- How to remove an element from a Java List?
- Java Program to Remove Repeated Element from An ArrayList
- Java Program to Remove Duplicates from an Array List
- Python program to remove row with custom list element
- How to remove an element from Array List in C#?
- How to remove an element from a list in Python?
- How to remove an element from an array in Java
- Remove an element from IdentityHashMap in Java
- Swift Program to Remove an Element from the Set
- Java program to remove duplicates elements from a List
- Java Program to Remove a Sublist from a List
- How to remove an element from ArrayList in Java?

Advertisements