Enumerate through a Vector using Java Enumeration Example
/* Enumerate through a Vector using Java Enumeration Example This Java Example shows how to enumerate through elements of a Vector using Java Enumeration. */ import java.util.Vector; import java.util.Enumeration; public class EnumerateThroughVectorExample { public static void main(String[] args) { //create a Vector object Vector v = new Vector(); //populate the Vector v.add("One"); v.add("Two"); v.add("Three"); v.add("Four"); //Get Enumeration of Vector's elements using elements() method Enumeration e = v.elements(); /* Enumeration provides two methods to enumerate through the elements. It's hasMoreElements method returns true if there are more elements to enumerate through otherwise it returns false. Its nextElement method returns the next element in enumeration. */ System.out.println("Elements of the Vector are : "); while(e.hasMoreElements()) System.out.println(e.nextElement()); } } /* Output would be Elements of the Vector are : One Two Three Four */
Bookmark/Search this post with:
Suggested Reading
| Oracle Magazine |
|
Contains technology strategy articles, sample code, tips,
Oracle and partner news, how to articles for developers and DBAs, and
more.
Cost: FREE
View/Subscribe
|
|
| NASA Tech Briefs |
|
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE
View/Subscribe
|
|
| FierceBiotech IT |
|
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE
View/Subscribe
|
|
| Simply SQL |
|
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE
View/Subscribe
|
|
| Simply JavaScript |
|
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE
View/Subscribe
|
|
| PCMag.com's What's New Now |
|
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE
View/Subscribe
|
|
Could not find what you are looking for? Search Java Examples
|
|
|
|