-2

I have a list of list in java where all the elements are string like below,

     [livelongandprosper, 2, 1]
     [deals, 11, 1]
     [SEO, 5, 1]
     [Bible, 8, 1]
     [EarnHistory, 2, 1]
     [God, 2, 0]
     [inktober2017, 3, 0]
     [Brand, 22, 1]
     [CoreyFedman, 1, 1]
     [HappyHalloween, 5, 0]
     [innisfree, 1, 1]
     [WorldSeries, 3, 1]
     [Scocco, 1, 1]

How can I sort the values of the above list of list on the basis of values in second column and in descending order?

  • Collections.sort(lss, new Comparator>>(){ public int compare(List o1, List o2) { //Simple string comparison here, add more sophisticated logic if needed. return o1.get(1).compareTo(o2.get(1)); } }); This is not working – Kartik Khurana Nov 01 '17 at 01:51
  • Can you actually write Java? Because this sounds as if you'd be better off learning some language basics before trying those tasks – Felix Dombek Nov 01 '17 at 01:53

1 Answers1

-1

Use a comparator, or implement comparable on the type which populates the list. And then use Collections.sort();

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311