permaculture playing cards*
The moose likes Beginning Java and the fly likes On what circumstances the ArrayList, LinkedList, Vector will be used. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "On what circumstances the ArrayList, LinkedList, Vector will be used." Watch "On what circumstances the ArrayList, LinkedList, Vector will be used." New topic
Author

On what circumstances the ArrayList, LinkedList, Vector will be used.

ssantha kumar
Greenhorn

Joined: Aug 18, 2006
Posts: 7
On what circumstances the ArrayList, LinkedList, Vector will be used?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Don't use Vector if you can help it. Use ArrayList instead. Have you been through the Java Tutorial about collections? You will find more details in there.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

To answer in short, when you want to deal with heterogeneous elements in one container, that's why Collections are there and the aforementioned elements are all a part of Collections in Java.

The term heterogeneous means elements of different/dissimilar kind which is contradicting to arrays as arrays can only store the elements of same kind.

You may go through the link given by Campbell for more detailed information.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Raghavan Muthu]: To answer in short, when you want to deal with heterogeneous elements in one container, that's why Collections are there

Nonsense. Collections are there to deal with groups of elements, either heterogeneous or homogeneous. I would argue that they're much more effective at dealing with homogeneous elements. Sure, it's possible to create heterogeneous collections. But why? It's certainly possible to to create homogeneous collections as well:

See? Easy.

To consider the original question:

ArrayList is generally what you should use in most cases when you want some sort of collection.

LinkedList is a good alternative if you are frequently inserting or deleting from the beginning of the list, or from the middle (using an iterator).

Vector is used only by unwashed savages. Books that recommend Vector should be simply ignored - they are too old to be useful. Anyone who attempts to describe a Vector as "thread-safe" should be shot on sight. Seriously, these people are idiots, and should be kept as far as possible from working coders.

If you have an ancient textbook which uses the term Vector, simply pretend that they said ArrayList instead. Ignore any discussion of how Vector is "thread-safe", as the author doesn't know what he's talking about - otherwise, Vector can be easily replaced with ArrayList.


"I'm not back." - Bill Harding, Twister
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Thank you Jim.

Obviously, they are here to "deal with the group of elements" precisely as the term 'Collection' literally means.

I agree that if at all you have a facility to deal with heterogeneous elements, that indeed facilitates for homogeneous elements as well. But as such, the importance of Collections were said to deal with heterogeneous elements right?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Sorry, but I really don't understand what you mean here. If dealing with heterogeneous elements was particularly important, an Object[] array did that well enough before Collections were around. Yes, Collections can deal with heterogeneous types, true, but I don't see why anyone should consider this terribly important.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: On what circumstances the ArrayList, LinkedList, Vector will be used.