<< Chapter < Page Chapter >> Page >

Ordered is not the same as sorted

Note that an ordered collection is not the same as a sorted collection.

The fact that the collection is ordered derives from the fact that each element in the collection has a specific position specified by anindex.

In a sorted collection, the position of each element is determined by its value relative to the values of its predecessors and successors.

Oracle goes on to say, "Unlike sets, lists typically allow duplicate elements. More formally, lists typically allow pairs of elements e1 and e2 suchthat e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all."

Is ascending sort order always required?

Not all implementations of the Collection interface maintain the elements in ascending sort order. Some may, and others do not. Forexample, as discussed above, implementations of the List interface (such as ArrayList ) do not maintain their elements in sorted order at all. In other words, the position of an element in an ArrayList does not depend on the value of the element.

On the other hand, implementations of the interface named SortedSet (such as TreeSet ) and the interface named SortedMap do maintain their elements in sorted order. However, that order is not necessarily ascending.

When an object is instantiated from a class that implements the SortedSet interface, the sorting order for that object can be established by providing anobject instantiated from a class that implements the Comparator interface. In that case, the author of the class that implements the Comparator interface determinesthe order imposed on the elements in the collection.

Does case matter in String objects?

For example, if your SortedSet object contains references to String objects, the natural ascending sort would take the difference between upper caseand lower case characters into account.

However, you might prefer that case be ignored when establishing the sorted order. You can accomplishthis by providing an object of a class that implements the Comparator interface and which defines the compare method and the equals method in such a way as to eliminate case considerations for comparisons of String objects.

Sub-interfaces have more stipulations

As you progress down the inheritance hierarchy, you find that additional stipulations apply at each level of inheritance. As an example, accordingto Oracle, "The Set interface places additional stipulations, beyond those inherited from the Collection interface, on the contracts of all constructorsand on the contracts of the add , equals and hashCode methods."

The important point is that specific sub-interfaces of the Collection interface can define requirements that do not apply to all sub-interfaces of the Collection interface.

Stipulations on set

For example, the add method of the Set interface stipulates the following:

"Adds the specified element to this set if it is not already present."

On the other hand, the add method of the Collection interfacesimply states:

"Ensures that this collection contains the specified element."

Questions & Answers

anyone know any internet site where one can find nanotechnology papers?
Damian Reply
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?