<< Chapter < Page Chapter >> Page >

Thus, the contract for the add method of an object of a class that implements the Set interface is more specialized than the contract for the add method of an object of a class that implements the Collection interface.

An additional stipulation on the constructor for a Set object is that all constructors must create a set that contains no duplicate elements.

Stipulations on SortedSet

The SortedSet interface extends the Set interface. The SortedSet interface contains the following stipulation that makes it more specialized than a Set .

"A set that further guarantees that its iterator will traverse the set in ascending element order, sorted according to the natural ordering of itselements (see Comparable ), or by a Comparator provided at sorted set creation time."

We will end with a quiz

I'm going to finish this module with several questions in the form of a quiz. To ensure that this is a learning experience, I will provide an explanation inaddition to the answer for each question.

Question 1

True or False? A collection that implements the List interface maintains its elements in ascending alphanumeric order.

The answer to question 1 is False. Unlike collections that implement the SortedSet interface, the order of the elements in a collection that implements the List interface is not based on the values of the objects referred to by the elements in the list.

Question 2

True or False? A collection that implements the List interface is an unordered collection.

The answer to question 2 is also False. A collection that implements the List interface is an ordered collection (also known as a sequence) . According to Oracle, "The user of the interface has precise control over where in the list each element is inserted." Elements can be inserted and retrieved on the basis of their integer index (position in the list) using the following methods:

  • add(int index, Object element)
  • get(int index)

Valid index values are positive integers that begin with zero. When the add method is used to insert an element at a specific position in the sequence, the element currently at that position (if any) and any subsequent elements are shifted toward higher index values to make room for thenew element.

Another version of the add method takes a reference to an object as an incoming parameter and appends the specified element to the end of thecollection.

The get method simply returns the element at the specified position in the collection.

The List interface also declares various other methods that can be used to manipulate the contents of the collection.

Question 3

True or False? A collection that implements the List interface is allowed to contain duplicate values.

The answer to question 3 is True. Unlike a collection that implements the Set interface, a collection that implements the List interface is typically allowed to contain duplicate values. More formally, accordingto Oracle, "lists typically allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allownull elements at all."

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