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

Iterator on Vector

Sun Oct 21, 2012 7:42 pm

Iteration on Vector list , we have to mention synchronized and safe in mutli-threaded environments but little slower than ArrayList(Not Synchronized and less safe) .

Code:


import java
.util.Iterator;
import java.util.Vector;

public class ArraysWork {

    public static void main(String[] args) {
        Vector vectorObject = new Vector();
        String cityStrings[] = {"Newyork", "Toronto", "Delhi", "Cairo"};
        for (String str : cityStrings) {
            vectorObject.add(str);
        }
        /*
         *
         * Printing the content vector
         */
        Iterator vectorIterator = vectorObject.iterator();
        for (; vectorIterator.hasNext();) {
            System.out.println(vectorIterator.next());
        }

    }
}
 


The output of this script:
Code:
NewYork
Toronto
Delhi
Cairo



To Remove all the content of Vector use Clear function as follows:
Code:
vectorObject.clear();




Post a reply
  Related Posts  to : Iterator on Vector
 iterator on list     -  
 Iterator interface     -  
 Removing elements from array list with the iterator     -  
 C++ Vector capacity     -  
 Vector class     -  
 vector front     -  
 Data Structures: Vector     -  
 count elements in a vector     -  
 Write Vector list to File     -  
 Support Vector Machine coding on Matlab...     -  

Topic Tags

Java Collections