wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Type Collection 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 » Java » Beginning Java
Bookmark "Type Collection" Watch "Type Collection" New topic
Author

Type Collection

Alan Jackson
Greenhorn

Joined: Oct 26, 2004
Posts: 26
I was wondering, how does type collection work? If Im wanting a list of files returned as a collection, how would I do it?
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
Collection

If you'd like a more specific answer, ask a more specific question. Anytime you return a List, you are returning a Collection, as List implements Collection.
[ November 11, 2004: Message edited by: Nick George ]

I've heard it takes forever to grow a woman from the ground
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I think most introductory Java texts dedicate at least a whole chapter to the Collections framework. This should give you an idea of how broad the topic is. The link Nick gave to the API docs is good for reference, but probably doesn't help you understand how to use it. As Nick mentioned, you need to be more specific about which type of Collection you want to use. In this case, List sounds appropriate. Now you need to decide, what type of List to use. There are basically two kinds of lists: linear and random access. If you only need to access the elements in order, a linear LinkedList is appropriate. However, a random access list is more popular since it is more like an array (i.e. you can efficiently access any element by a given index). In this case, you can use either ArrayList or Vector. ArrayList is the usual choice. The major difference is that Vector is designed to be thread safe. So unless you are writing a threaded program, you should avoid the overhead in Vector and just use ArrayList instead.

Well, this is only a general overview. Please feel free to ask more specific questions that pertain to your particular problem.

Keep Coding! (TM)

Layne


Java API Documentation
The Java Tutorial
 
 
subject: Type Collection