Hello, in this post we will see a java example program. We will learn how to read all elements in vector using an iterator.
WHAT IS AN ITERATOR ?
in Java, Iterator is an interface that available in collection framework in java.util.package. It’s a java cursor to iterate a collection of object.
Iterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.
Here you go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package com.practice.house; import java.util.Iterator; import java.util.Vector; /** * * @author marifurr */ public class JavaVector { public static void main(String[] args) { Vector<String> vct = new Vector<String>(); //adding elements vct.add("First"); vct.add("Second"); vct.add("Third"); vct.add("Random"); //Iterator<E> iterator() //Returns an iterator over the elements in this list in proper sequence. Iterator<String> itr = vct.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } } } |
Sample Output :
Thanks for reading this post. if you have any comments or question or challenge please post it down below there. we will be happy to keep in touch with you.

Java – PHP – Python – Dart – Flutter – MySql – Spring – Hibernate – JavaScript – jQuery – BootStrap 4 – CSS – HTML
I love to explore new technologies. If you like my tutorials please share your thoughts about my work.
Check out my YouTube Channel For Video Tutorials.
To Hire Me Please Contact Me Through Social Media or https:www.amialif.com
If you want to help others by doing donation please Help Them.
You also can connect with me via social media. Thanks
Can you inform me what system are you utilizing on this web
site?