Professional Documents
Culture Documents
Enumerate Through A Vector Using Java Enumeration Example - Java Examples - Java Program Sample Source Code
Enumerate Through A Vector Using Java Enumeration Example - Java Examples - Java Program Sample Source Code
EnumeratethroughaVectorusingJavaEnumerationExample|JavaExamplesJavaProgramSampleSourceCode
EnumeratethroughaVectorusingJavaEnumerationExample
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.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
/*
EnumeratethroughaVectorusingJavaEnumerationExample
ThisJavaExampleshowshowtoenumeratethroughelementsofaVector
usingJavaEnumeration.
*/
importjava.util.Vector
importjava.util.Enumeration
publicclassEnumerateThroughVectorExample{
publicstaticvoidmain(String[]args){
//createaVectorobject
Vectorv=newVector()
//populatetheVector
v.add("One")
v.add("Two")
v.add("Three")
v.add("Four")
//GetEnumerationofVector'selementsusingelements()method
Enumeratione=v.elements()
/*
Enumerationprovidestwomethodstoenumeratethroughtheelements.
It'shasMoreElementsmethodreturnstrueiftherearemoreelementsto
enumeratethroughotherwiseitreturnsfalse.ItsnextElementmethodreturns
thenextelementinenumeration.
*/
System.out.println("ElementsoftheVectorare:")
while(e.hasMoreElements())
System.out.println(e.nextElement())
}
}
/*
Outputwouldbe
ElementsoftheVectorare:
One
Two
Three
Four
*/
http://www.javaexamples.com/enumeratethroughvectorusingjavaenumerationexample
1/3
9/18/2015
EnumeratethroughaVectorusingJavaEnumerationExample|JavaExamplesJavaProgramSampleSourceCode
Tweet
Advertisement:
ReceiveLatestJavaexamplesinyouremail:
Subscribe
RelatedJavaExamples
GetEnumerationoverJavaVectorExample
CreateJavaArrayListFromEnumerationExample
GetEnumerationoverJavaArrayListExample
GetEnumerationoverJavaHashSetExample
AddanelementatspecifiedindexofJavaVectorExample
SimpleJavaVectorExample
http://www.javaexamples.com/enumeratethroughvectorusingjavaenumerationexample
2/3
9/18/2015
EnumeratethroughaVectorusingJavaEnumerationExample|JavaExamplesJavaProgramSampleSourceCode
CopyElementsofOneJavaVectortoAnotherJavaVectorExample
GetSizeofJavaVectorandloopthroughtheelementsExample
0Comments
Recommend
javaex
Share
Login
SortbyBest
Startthediscussion
Bethefirsttocomment.
Subscribe
AddDisqustoyoursite
Privacy
http://www.javaexamples.com/enumeratethroughvectorusingjavaenumerationexample
3/3