Switch to full style
Java Collections classes examples .
Post a reply

Removing elements from array list with the iterator

Sun Oct 21, 2012 1:22 pm

Remove elements from array list using iterator object :
Code:

import java
.util.ArrayList;
import java.util.Iterator;

public class ArraysWork {

    public static void main(String[] args) {


        ArrayList charsList = new ArrayList();
        for (char alphabet = 'A'; alphabet < 'H'; alphabet++) {
            charsList.add(alphabet);
        }
        Iterator iterator1 = charsList.iterator();
        while (iterator1.hasNext()) {
            System.out.print(iterator1.next() + " \n");
            iterator1.remove();
        }
        Iterator iterator2 = charsList.iterator();
        while (iterator2.hasNext()) {
            System.out.print("The array is not empty");

        }

    }
}
 


The output is :
Code:







G




Post a reply
  Related Posts  to : Removing elements from array list with the iterator
 iterator on list     -  
 Add border around ordered list elements     -  
 Listing elements using list components in J2me     -  
 Add elements to the end of an array     -  
 Elements of the enumerated array are numbers     -  
 Return an array with elements in reverse order     -  
 find out the number of elements in an array of 8-bit element     -  
 Convert normal array to a list     -  
 removing focus border from a HTML element     -  
 Iterator interface     -  

Topic Tags

Java Collections