• 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

more errata from Mughal

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was reading through chapter 11 on the Collections framework and found this error that is illustrated by an inconsistency between the venn diagram on p.328 and review question #11.11:
I think this must be a mistake--it's suggested that the Collection.addAll() method operates according to the union principle:
{1,3,2}U{1,3,2} = {1,3,2}
but evidently this is not the case as the example
shows.
If addAll() operated according to set union principle than the call to subList(2,5) on line 12 would produce IndexOutOfBoundsException.
I wonder if anyone can corroborate whether or not my assumption is correct?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having a look at the source code of class ArrayList, the addAll method looks like this:

We can easily see that there is no comparison whatsoever between the element added and the elements already present in the list. Thus, all elements in the argument collection are added to the target collection even if an element is alread present. Moreover, the Collection interface does not specify that the addAll() method should use the union principle.
 
mike hanser
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply val, it just bugs the heck outta me that such a well quoted book should have these mistakes in it.
mike
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no kidding
 
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic