• Post Reply Bookmark Topic Watch Topic
  • New Topic

issue with stack  RSS feed

 
Sundar Murthi
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Prints true.


Any idea how to solve this with stack?
 
Sundar Murthi
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even outputs true.

Any document or thread explain this?
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I imagine that the stack is only seeing the object type ArrayList and not the type of the ArrayList(i.e. String, Integer). The underlying functioning of the contains method calls the equals method. So I think that all the call to contains is seeing is two ArrayList objects with no elements and it is evaluating to true. Try adding an element to one of the ArrayLists then comparing.

Hunter
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the API documentation. It says
if they contain the same elements in the same order.
Your two Lists both contain the same elements, ie nothing. So, according to that description they are equal. The actual type parameter doesn't affect that; the type parameters are removed by erasure anyway.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!