Win a copy of Terraform in Action this week in the Cloud 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

chap 7 doubt

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Arrays.sort()
methods that sort primitives always sort based on natural order.

Don't be fooled by
an exam question that tries to sort a primitive array using a Comparator.


I am not able to understand above line in KB book page 256
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mukki pandey:
The Arrays.sort()
methods that sort primitives always sort based on natural order.

Don't be fooled by
an exam question that tries to sort a primitive array using a Comparator.


I am not able to understand above line in KB book page 256



That does mean that implementation of Arrays.sort() method does natural
sorting of primitives.

While using Comparator you can achieve other ways of sorting like reverse
order as well. For that you need to implement compare() method of Comparator.

Don't get fooled means, see the implementation of Comparator's method before
coming to conclusion what exactly is happening inside the method, or say
what kinda sorting is implemented inside. Do not come to result that the
sorting is natural order only.

reply
    Bookmark Topic Watch Topic
  • New Topic