This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Vector" Watch "Vector" New topic
Author

Vector

Marcos Vilela
Greenhorn

Joined: Jul 06, 2005
Posts: 18
Which of the following classes, will return elements in the order they were added (first in first out) when accessed via an iterator?

Vector. True
LinkedHashSet. True.

Why Vector?




output = Two , Ten , Three , One.

It's a little trick because if you use add with a position it will be wrong..

I need help..

Thanks
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

The Vector implementation is basically an ArrayList, but is thread-safe, so insertion order will be the order you get byt default.


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA

Live life to an interface, not an implementation!
lauren bai
Greenhorn

Joined: Apr 08, 2005
Posts: 18
It's a little trick because if you use add with a position it will be wrong..

I don't know why you change the position since it's not the question said
in the order they were added (first in first out)


SCJP (In Progress)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Vector