aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions about collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Questions about collections" Watch "Questions about collections" New topic
Author

Questions about collections

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
I keep running into confusion while trying to make since of all the different collection classes/interfaces.

First off, why doesn't the Map interface extend the Collection interface? Is it solely because a Map takes a key/value pair?

Also, What are the properties of a Collection (capital C - interface)? What I mean is a List (which extends Collection) is unique because it defines the methods that relate to an index like get(int). So what defines something that IS-A Collection that makes it unique from something that IS-A Map?

I hope that made sense.


SCJA
~Currently preparing for SCJP6
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

why doesn't the Map interface extend the Collection interface? Is it solely because a Map takes a key/value pair?


Yes. Collection represent a collection of objects while a Map represents a key/value pair.

what defines something that IS-A Collection that makes it unique from something that IS-A Map?


Again I think the answer is the same. Collection interface provides methods such as add which lets you add an element to the collection. Map provides methods such as put which takes two arguments i.e. a Key and Value...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Thanks for the reply Ankit! I do understand that... I guess my question was more focused on the reason behind why they did it that way? For instance why didn't they just have the Map interface extend the Collection interface and then overload the add method to accept 2 objects instead of 1? I know they had a good reason, and I'm sure it's a simple one... I just keep thinking that if I can understand why it is set up the way it is then I'll also understand much better how it works (and why).

Thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions about collections