• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide Chapter 3 Question 19

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Which of the following are true? (Choose all that apply)
A. Two arrays with the same content are equal.
B. Two ArrayLists with the same content are equal.
C. If you call remove(0) using an empty ArrayList object, it will compile successfully.
D. If you call remove(0) using an empty ArrayList object, it will run successfully.
E. None of the above.



The books says B and C are the correct answer.

ArrayList does override equals() and defines it as the same elements in the same order.



About answer B, I think it's wrong.
English is not my first language and I interpret "same content" as "contains the same elements ignoring the order of the elements".
Is my interpretation of "same content" wrong?
 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Book's explanation is correct.

Frenkel Smeijers wrote:English is not my first language and I interpret "same content" as "contains the same elements ignoring the order of the elements".


Mine too but I think It's not about what we think but what implementer of the language Or that method says since Java 8 Doc: equlas(Object o) method says

Java 8 Doc: equals(Object o) method of List wrote:In other words, two lists are defined to be equal if they contain the same elements in the same order.

 
and book says the same on page no 133 equals() method.

Is my interpretation of "same content" wrong?

I think yes, at least in this scenario.

 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic