aspose file tools*
The moose likes Java in General and the fly likes why does my code print out the same word 10 times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "why does my code print out the same word 10 times" Watch "why does my code print out the same word 10 times" New topic
Author

why does my code print out the same word 10 times

jason lunt
Greenhorn

Joined: Nov 20, 2002
Posts: 7
i have this in my code but it prints out the element what i want but it will print it 12 times which is how many elements are in the vector how do i get it to print it out only once?
for (Enumeration e = v.elements();e.hasMoreElements() {
String se = (String)e.nextElement();
String s1 = (String)v.get(1);

System.out.println(s1);
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Why do you have this line?
String s1 = (String)v.get(1);
Why are you printing s1 rather than se?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
jason lunt
Greenhorn

Joined: Nov 20, 2002
Posts: 7
well i want it to print out the first element of the vector and that is how i thought i should do it any other suggestions woulud be most pleased thanks
jason
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
In that case, why are you using an Enumeration at all?
jason lunt
Greenhorn

Joined: Nov 20, 2002
Posts: 7
could you please give me some ideas in what i should use
thanks
jason
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Take a look at The J2SE Documentation for the Vector class. You should note a couple of methods that you could use to get the first component of a Vector. Note that I've emphasized the word get and that the first component in a Vector is at index 0.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
jason lunt
Greenhorn

Joined: Nov 20, 2002
Posts: 7
cheers everyone for the ideas and that
i have found it now
and it works thanks alot
jason
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why does my code print out the same word 10 times