Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Sorting issue

 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following categories (1D, 2D, 3D, 2DD, and 3DD) and each one has a 1 to 20 rank associated with them. What is the easiest way to sort the values so they arrange like this :
 
lowercase baba
Posts: 12988
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried?
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had copied a line such as :

but it wasn't working exactly as planned, the solution was replacing <=> with cmp.
 
fred rosenberger
lowercase baba
Posts: 12988
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Hunter wrote: the solution was replacing <=> with cmp.


I don't understand this.

regardless...

The first thing you need to do is define how EXACTLY you want things sorted. Posting an example is fine...but it is not a spec.

My guess is that you might need to break each category into components....so "1D 1" needs to be parsed into "1D" and "1". I believe that if you sort on the second part, then do another sort on the first (assuming you are using a stable sort), it will give you want you want.

There may be some tweaks needed on String vs numeric sorts, but again, without details of what you really need, it's hard to say.

 
Let nothing stop you! Not even this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic