<< Chapter < Page Chapter >> Page >

While you will ultimately need to understand how to use Generics, that is a very complex topic. An understanding of Generics is beyond the scope of thiscourse. Therefore, for purposes of this course, you can simply ignore those warnings.

Discussion

We will start with a quiz

I am going to begin this module with a quiz just to make sure that you are still awake. Is the following statement Trueor False?

The TreeSet class is a direct implementation of the Collection interface.

The answer is False.

The TreeSet class is not a direct implementation of the Collection interface. Rather, the TreeSet class is a direct implementation of the SortedSet interface. The SortedSet interface extends the Set interface, and the Set interface extends the Collection interface.

The interface hierarchy for the Java Collections Framework is shown below:

  • Collection
    • Set
      • SortedSet
    • List
    • Queue
    • Deque
  • Map
    • SortedMap

As you learned in an earlier module, the Java Collections Framework doesn't have a single root. As shown above, there are two distinct trees in theframework -- The Collection hierarchy and the Map hierarchy.

The root of the Collection hierarchy

The Collection interface is the root of the collection hierarchy. The Java Collections Framework doesn't provide any direct implementations of the Collection interface. All of the implementations of the interfaces in the Collection hierarchy implement one of the sub-interfaces of the Collection interface.

What does Oracle say about this?

Here is what the Oracle documentation has to say on the topic of the Collection interface:

"The SDK does not provide any direct implementations of this interface: it provides implementations of more specific sub-interfaces like Set and List . This interface is typically used to pass collections around and manipulate them wheremaximum generality is desired."

The Oracle documentation also states:

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

What about duplicate elements?

Some implementations of Collection allow duplicate elements, and others do not. Implementations of the List interface (such as ArrayList ) allow duplicate elements. Implements of Set and SortedSet (such as TreeSet ) do not allow duplicate elements. This was illustrated in an earlier module.

A sample program in that earlier module created two collection objects and applied the polymorphic add method to add the same elements to each collection. One of the collection objects was of type ArrayList , and the other collection object was of type TreeSet . The elements added to each collection contained one pair of duplicate elements. The duplicate elementwas automatically excluded from the TreeSet object, but was retained in the ArrayList object.

What is a set?

According to Oracle, a Set is a "collection that contains no duplicate elements ... this interface models the mathematical set abstraction."

An object of type Set is typically used to model collections such as Social Security numbers, where duplicates are not allowed.

What is a list?

Also according to Oracle, a List is "An ordered collection (also known as a sequence). The user of this interface has precise control over where in thelist each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list."

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask