<< Chapter < Page Chapter >> Page >

Display the collection's contents

Then, as before, the code in Listing 4 gets an iterator and uses it to access and display the contents of the ArrayList collection.

The ArrayList class implements the List interface, which does not prohibit duplicate elements, and does not maintain its elements in sortedorder. Therefore, in this case, the following text was displayed:

44321

All five element values are displayed, including the duplicate, in the order in which they were added to the list.

The important point

The important point is that although the fillIt method calls the same method name ( add ) on each of the collection objects, the behavior of that method is different in each case. In both cases, the behavior isappropriate for the underlying data structure. Furthermore, the underlying data structure isn't even known to the fillIt method.

No duplicate elements in ascending order

In the first case, where the underlying data structure was a TreeSet object (type SortedSet ), the duplicate element was eliminated, and the elements were stored so as to be accessible in ascending order.

Duplicates allowed with no sorting

In the second case, where the underlying data structure was an ArrayList object (type List ), all five elements, including the duplicate element were stored in the collection. Furthermore, they were stored and laterretrieved in the same order in which they were added.

Structure of the core interfaces

The core collection interfaces in the Java Collections Framework do not all extend from a common root interface.

Rather, the inheritance structure of the core interfaces is shown below. Indentation is used to indicate the parent-child relationships among the interfaces.

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

A Map is not a true Collection

As you can see, that there is no common root interface. Rather, there are two distinct trees, one rooted by Collection and the other rooted by Map . According to The Java Tutorial from Oracle, "a Map is not a true Collection." I will have more to say about this in a future module.

Some operations are optional

Every class that implements an interface in the tree rooted in Collection is not required to support all of the methods (operations) declared in the Collection interface.

Rather, some of the methods in the Collection interface are designated as "optional operation" in the documentation. (See the list of optional methods for the Collection interface below.)

According to the contract for the Collections Framework, if a given implementation doesn't support a specific method, it must throw an UnsupportedOperationException . The author of the implementation is responsible for providing documentation that identifies the optional operationsthat the implementation does and does not support.

Support for optional operations

This should not be an issue unless you are either defining your own implementation, or using an implementation defined by someone other than theprogrammers at Oracle. All of the general-purpose implementations from Oracle appear to support all of the optional operations.

Questions & Answers

Leo Robinson's definition
Adejimi Reply
how is equilibrium defined in financial markets?
Babakura Reply
the concept of it
DALOM
Country A has export sales 20 billion, government purchases 1000billion, business investment is 50 billion, imports are 40billion, and consumption spending is 2000billin. What is the dollar value of GDP ?
Habtamu Reply
what is determination of national income?
Waqar Reply
economic growth
Rukaiya
stock of capital
Rukaiya
we're RBI keep money with them
Anil
Y =C+l
Favour
evaluate the success affirmative action as one of south Africa's redress method
Tebatso Reply
what is market equilibrium
explorer Reply
it is a situation in which the supply of an item is exactly equal to it dd .
Ssmith
inder wat condition shld a firm stop production in both short n lungrun ?
Ssmith
what is 2nd degree price discrimination?
Ssmith
what is quantity
Tettey
what is quantity2
Deji Reply
An indefinite amount of something.
explorer
what is demand
Kaman Reply
in ordinary sense demand means desire
Khalid
demand in economics means both willingness as well as the ability to purchase a commodity by paying a price an also its actuall purchase
Khalid
what is absolute advantage
Khalid
demand refers to the various quantity of goods and services that consumers are willing and able to purchase at a particular period of time all other things been equal
Dela
The amount of a good or service that consumers are willing to buy at a particular price.
explorer
what is cost pull inflation?
oru
what is utility
oru
what is cost pull inflation?
oru
demand is economic principle referring to a consumer's desire and willingness to pay a price for a specific or service..
Babakura
utility is the among of certisfaction driving from using a comundity
Anas
pull cost of inflation hight population unemployment to some of The country members poor government system
Anas
what is a buffer scheme
Lukong
state the second law of demand and supply
Ahmadou Reply
state the law of diminishing marginal utility
Ahmadou
dt know WATS the answer
Rukundo
mention and explain two Bank I financial institutions and two non baking financial institutions
Onah Reply
wat is demand pull inflation
Tony Reply
Demand-pull inflation is asserted to arise when aggregate demandin an economy outpaces aggregate supply. It involvesinflation rising as real gross domestic product rises and unemployment falls, as the economy moves along the Phillips curve.
kevin
Perfectly elastic demand
Abubakar Reply
this is a form of demand where goods are demanded at a constant price
Rukundo
what inelastic demanding
Koire
demand of any good demanded more after a certain period. if a commodity prices may high and scarcity of that resources.
Anil
cannot demand more
Anil
what is cross-elasticity of demand
Miles Reply
cross elasticity of demand is an economic concept that measures the responsiveness in the quantity demand of one good when a change in price takes place in other good
Mallekha
this is responsiveness quantity demanded keeping other factors constant
Rukundo
what economic growth
Rukundo Reply
conditions of perfect market
NdzAlama Reply
CONDITIONS OF PERFECT MARKET: 1. Perfect competition(PC): no increasing returns, many buyers and sellers, all are price takers, not prices makers. 2. Perfect Information (PI): buyers and sellers know all they need to know about what they are buying and selling to make the right decisions.
Mallekha
3. Complete Markets(CM): no externalities or public goods, no transactions costs, "thick" markets.
Mallekha
nice contributor
Mohammed
A numerous downsized market that does not meet standards.
LaTasha
A Perfect Market is a numerous downsized market that does not meet standards.
LaTasha
what is a market
Ahmadou
is place where buyers and sellers met together for the purpose of buying and selling of good and services
Babakura
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
China
Cied
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
Porter
many many of nanotubes
Porter
what is the k.e before it land
Yasmin
what is the function of carbon nanotubes?
Cesar
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
AMJAD
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
AMJAD
what is system testing
AMJAD
what is the application of nanotechnology?
Stotaw
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
Azam
anybody can imagine what will be happen after 100 years from now in nano tech world
Prasenjit
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
Azam
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
Prasenjit
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
Damian
silver nanoparticles could handle the job?
Damian
not now but maybe in future only AgNP maybe any other nanomaterials
Azam
can nanotechnology change the direction of the face of the world
Prasenjit Reply
At high concentrations (>0.01 M), the relation between absorptivity coefficient and absorbance is no longer linear. This is due to the electrostatic interactions between the quantum dots in close proximity. If the concentration of the solution is high, another effect that is seen is the scattering of light from the large number of quantum dots. This assumption only works at low concentrations of the analyte. Presence of stray light.
Ali Reply
the Beer law works very well for dilute solutions but fails for very high concentrations. why?
bamidele Reply
in a comparison of the stages of meiosis to the stage of mitosis, which stages are unique to meiosis and which stages have the same event in botg meiosis and mitosis
Leah Reply
Got questions? Join the online conversation and get instant answers!
QuizOver.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?

Ask