Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

ArrayList

 
Ranch Hand
Posts: 125
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm studying Java 8 OCA 1Z0-808 using the book by Jeanne Boyarsky and Scott Selikoff.

Chapter 3 review question #19 says:

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.


Correct answer is A and B.

But why B?
If 2 same content ArrayLists using ==, they are NOT equal.
But if 2 same content ArrayLists using equals() method, they are equal.
 
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have looked into the chapter she had use the word equals in context of the equals() method(several times) so if the contents inside the arrays or list are same then they would be equal.
by the way as per "==" they may not be equal.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

henry leu wrote:If 2 same content ArrayLists using ==, they are NOT equal.
But if 2 same content ArrayLists using equals() method, they are equal.


If that's your reasoning why you doubt about answer B, I wonder why you don't doubt about answer A Because the same remark applies to arrays as well (as illustrated in the following code snippet)
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic