File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes  container, Iterators , Collection ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " container, Iterators , Collection ?" Watch " container, Iterators , Collection ?" New topic

container, Iterators , Collection ?

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Hi there,
a) Can you explain what is

1. container
Is array is also a container ?

2. Iterators
Why Iterators ?

3. Collection
4. Collections
What is the relation between Collection and Collections.

5. Comparable
6. Comparator
What is the relation between Comparable and Comparator.

nikos sokaf
Ranch Hand

Joined: May 01, 2004
Posts: 57
The informations you need you will find on tutorials...

I suggest you to check out all the java.util.* package.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Intermediate forum..

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Warren Dew
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
2. While iterators don't always save much typing over manual iteration, using them tends to result in a fewer bugs, and thus less debugging time. They also tend to be a bit more legible, once you get used to them.

3&4 A Collection is just that - a collection of objects. The Collections class provides useful static methods for use with the various Collection subclasses.

5&6 A Comparator is a thing that does the comparing. Something that implements Comparable is something that gets compared.

A Comparator is typically written to compare two things that aren't normally compared, or to compare them in a different way than normal. Things that implement Comparable are expected to be compared, and can be compared without writing an explicit Comparator class.
Herb Schildt
Ranch Hand

Joined: Oct 01, 2003
Posts: 239

As a point of interest, with the new Java 2, v1.5 (tiger), Java supports a "for-each" style of for loop that automatically iterates over a collection. Its use simplifies the code that cycles through a collection. Given your current line of questioning, you might want to check it out.

For my latest books on Java, including my Java Programming Cookbook, see
Don't get me started about those stupid light bulbs.
subject: container, Iterators , Collection ?