Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sorting  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have data in a file like
1,2,3,1WM,1WM5,1WM2,15MN,15MN10,9MN,9MN1,
11XL,11XL2,5XX,1MN,1MN2,1LM

i have to read data and need to sort like the following
1,1LM,1MN,1MN2,1WM,1WM5,2,3,5XX,9MN,9MN1,11XL,11XL2,15MN,15MN10

Please can any one help me.
 
Marshal
Posts: 58363
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried a Comparator? Have you written down on paper what the rules are to provide a "natural ordering"?
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you have to use Comparator for that purpose and the logic could be like you have to get substring and then have to sort those parts.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!