• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList sorting using comparator performance

 
Rahul Nair
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello Ranchers,

I have doubt about the sorting performance when using comparator.
Please consider the following code:

and

Which code is preferable if we compare the performance and why ?


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33691
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul,
What happened when you tried it by running against a large list?
 
Rahul Nair
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Jeanne,

I have not tried for large number of list. However my understanding is that the first code should be the choice ? Isn't it ?

Thanks,

Rahul
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33691
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea. If I wanted to know, I'd try it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic