aspose file tools*
The moose likes Beginning Java and the fly likes Regarding Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding Collections" Watch "Regarding Collections" New topic
Author

Regarding Collections

Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear friends,

What is the exact difference between Collection<E> and Collection<T>?
What is the exact difference between java.util.Collection and java.util.Collections?

Couldn't understand API explanation at my level.

Your kindly help needed.

Thanks in advance!!
Regards,
Vijay
krishnamoorthy kitcha
Ranch Hand

Joined: Feb 04, 2006
Posts: 96
Hi

Collection

The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements. Some collections allow duplicate elements and others do not. Some are ordered and others unordered. The SDK does not provide any direct implementations of this interface: it provides implementations of more specific subinterfaces like Set and List. This interface is typically used to pass collections around and manipulate them where maximum generality is desired.

Bags or multisets (unordered collections that may contain duplicate elements) should implement this interface directly.

All general-purpose Collection implementation classes (which typically implement Collection indirectly through one of its subinterfaces) should provide two "standard" constructors: a void (no arguments) constructor, which creates an empty collection, and a constructor with a single argument of type Collection, which creates a new collection with the same elements as its argument. In effect, the latter constructor allows the user to copy any collection, producing an equivalent collection of the desired implementation type. There is no way to enforce this convention (as interfaces cannot contain constructors) but all of the general-purpose Collection implementations in the SDK comply.

Collections

public class Collections
extends Object

This class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, and a few other odds and ends.

The documentation for the polymorphic algorithms contained in this class generally includes a brief description of the implementation. Such descriptions should be regarded as implementation notes, rather than parts of the specification. Implementors should feel free to substitute other algorithms, so long as the specification itself is adhered to. (For example, the algorithm used by sort does not have to be a mergesort, but it does have to be stable.)

See Also
Collection
Set
List
Map
Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Could anyone tell me
What is the exact difference between Collection<E> and Collection<T>?


Thank you,
Vijay
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

There is no difference. The <E> or <T> is the generic type of the collection, which is limiting the objects that can be added.

However, when declaring a class, it doesn't matter how you call it. There is no difference in the following pieces of code:

It's just a name (mostly a single letter) that the programmer thought would be readable. Mostly it is "T" for "type", "E" for "element", "K" for "key" and "V" for "value" (the last two mostly for maps).

As for using, this is when you "replace" the E/T with any class you want.
Collection<Integer> will be a collection that only accepts integers; Collection<String> will only accept strings, etc.

For instance, using the above example, you use SomeInterface<Integer>, the compiler treats the class as the following:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vijay Chandran
Ranch Hand

Joined: Jan 07, 2007
Posts: 178
Dear Rob,

Thank you very much for the reply.


Regards,
Vijay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Collections
 
Similar Threads
Question about generics
Portal7.0
About String
diffrence between collection n collections
init and context parameters