• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Type Collection

 
Alan Jackson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic