• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

OCP Chapter 3 Review question 14  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



t2 did specify a Comparator when calling the constructor, so it uses the compare() method, which sorts by the int.




" TreeSet<Sorted> t2 = new TreeSet<>(s1);  "
Why does TreeSet's constructor take s1 here? Can s1 treat as Comparator here? Thanks
 
author & internet detective
Posts: 39208
726
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passing a comparator parameter is optional. You can just write new TreeSet() and it will use the default sort order of the objects.

Or you can pass in a comparator and it will use that one instead.

As you probably noticed, evil cert book authors (and exam creators) can change the sort order to one you don't expect this way. Hee. Hee. <evil grin>
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!