Java Comparator.comparing not comparing?In Java how do you sort one list based on another?Order list by a related-list in JavaIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Comparing Java enum members: == or equals()?How do I convert a String to an int in Java?Creating a memory leak with JavaSwift Beta performance: sorting arrays

Removing the last element of a list

Can a ring of spell storing and access to Find spells produce an endless menagerie?

Why isn't 'chemically-strengthened glass' made with potassium carbonate? To begin with?

Why did other houses not demand this?

Why does the Starter Set wizard have six spells in their spellbook?

Is it legal to have an abortion in another state or abroad?

Heat lost in ideal capacitor charging

How to melt snow without fire or using body heat?

Freedom of Speech and Assembly in China

Gravitational Force Between Numbers

Should I split timestamp parts into separate columns?

A burglar's sunglasses, a lady's odyssey

Can a UK national work as a paid shop assistant in the USA?

Why did Jon Snow do this immoral act if he is so honorable?

Is this homebrew "Cactus Grenade" cantrip balanced?

3 prong range outlet

How did NASA Langley end up with the first 737?

Navigating a quick return to previous employer

If I arrive in the UK, and then head to mainland Europe, does my Schengen visa 90 day limit start when I arrived in the UK, or mainland Europe?

What were the Ethiopians doing in Xerxes' army?

Why do the i8080 I/O instructions take a byte-sized operand to determine the port?

What is the recommended procedure to land a taildragger in a crosswind?

What are these clip-like things?

Testing using real data of the customer



Java Comparator.comparing not comparing?


In Java how do you sort one list based on another?Order list by a related-list in JavaIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Comparing Java enum members: == or equals()?How do I convert a String to an int in Java?Creating a memory leak with JavaSwift Beta performance: sorting arrays






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








11















Following this question about sorting a list by another list, I tried to do the same thing - but from some reason it doesn't work for me. What am I missing?



 List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
nums.sort(Comparator.comparing(order::indexOf));
System.out.println(nums);

OUTPUT: [5.0, 0.9, 10.4]


It should be [0.9, 10.4, 5.0] (according to order). What am I not doing right?



EDIT: As most of you noticed, I got answer to the question I linked to all wrong. Here's what I actually want to do.










share|improve this question
























  • I'm not understanding why are you trying to sort nums with orders : looks like you simply wanna sort nums, why are you using order ?

    – Leviand
    May 16 at 9:52











  • Just noticed I wrote it wrong, edited it.

    – shakedzy
    May 16 at 9:53











  • ok now make sense :)

    – Leviand
    May 16 at 9:55











  • For this to work, each nums element must exist in order

    – Logan Wlv
    May 16 at 9:59

















11















Following this question about sorting a list by another list, I tried to do the same thing - but from some reason it doesn't work for me. What am I missing?



 List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
nums.sort(Comparator.comparing(order::indexOf));
System.out.println(nums);

OUTPUT: [5.0, 0.9, 10.4]


It should be [0.9, 10.4, 5.0] (according to order). What am I not doing right?



EDIT: As most of you noticed, I got answer to the question I linked to all wrong. Here's what I actually want to do.










share|improve this question
























  • I'm not understanding why are you trying to sort nums with orders : looks like you simply wanna sort nums, why are you using order ?

    – Leviand
    May 16 at 9:52











  • Just noticed I wrote it wrong, edited it.

    – shakedzy
    May 16 at 9:53











  • ok now make sense :)

    – Leviand
    May 16 at 9:55











  • For this to work, each nums element must exist in order

    – Logan Wlv
    May 16 at 9:59













11












11








11








Following this question about sorting a list by another list, I tried to do the same thing - but from some reason it doesn't work for me. What am I missing?



 List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
nums.sort(Comparator.comparing(order::indexOf));
System.out.println(nums);

OUTPUT: [5.0, 0.9, 10.4]


It should be [0.9, 10.4, 5.0] (according to order). What am I not doing right?



EDIT: As most of you noticed, I got answer to the question I linked to all wrong. Here's what I actually want to do.










share|improve this question
















Following this question about sorting a list by another list, I tried to do the same thing - but from some reason it doesn't work for me. What am I missing?



 List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
nums.sort(Comparator.comparing(order::indexOf));
System.out.println(nums);

OUTPUT: [5.0, 0.9, 10.4]


It should be [0.9, 10.4, 5.0] (according to order). What am I not doing right?



EDIT: As most of you noticed, I got answer to the question I linked to all wrong. Here's what I actually want to do.







java sorting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 16 at 10:09







shakedzy

















asked May 16 at 9:48









shakedzyshakedzy

1,31211639




1,31211639












  • I'm not understanding why are you trying to sort nums with orders : looks like you simply wanna sort nums, why are you using order ?

    – Leviand
    May 16 at 9:52











  • Just noticed I wrote it wrong, edited it.

    – shakedzy
    May 16 at 9:53











  • ok now make sense :)

    – Leviand
    May 16 at 9:55











  • For this to work, each nums element must exist in order

    – Logan Wlv
    May 16 at 9:59

















  • I'm not understanding why are you trying to sort nums with orders : looks like you simply wanna sort nums, why are you using order ?

    – Leviand
    May 16 at 9:52











  • Just noticed I wrote it wrong, edited it.

    – shakedzy
    May 16 at 9:53











  • ok now make sense :)

    – Leviand
    May 16 at 9:55











  • For this to work, each nums element must exist in order

    – Logan Wlv
    May 16 at 9:59
















I'm not understanding why are you trying to sort nums with orders : looks like you simply wanna sort nums, why are you using order ?

– Leviand
May 16 at 9:52





I'm not understanding why are you trying to sort nums with orders : looks like you simply wanna sort nums, why are you using order ?

– Leviand
May 16 at 9:52













Just noticed I wrote it wrong, edited it.

– shakedzy
May 16 at 9:53





Just noticed I wrote it wrong, edited it.

– shakedzy
May 16 at 9:53













ok now make sense :)

– Leviand
May 16 at 9:55





ok now make sense :)

– Leviand
May 16 at 9:55













For this to work, each nums element must exist in order

– Logan Wlv
May 16 at 9:59





For this to work, each nums element must exist in order

– Logan Wlv
May 16 at 9:59












4 Answers
4






active

oldest

votes


















17














You are sorting the numbers by their position in the order list, but none of the numbers occur in the order list. In this case, indexOf will return -1 for everything, meaning everything is equal to everything else. In such a case, the resulting sort order is unspecified - though you may realistically assume that it would not change.






share|improve this answer

























  • Oh, so I got it all wrong.. how then do I sort nums by order?

    – shakedzy
    May 16 at 9:56











  • @shakedzy I don't know what you mean by "sort nums by order"

    – Michael
    May 16 at 9:56











  • @Michael I believe using order as the keys for sorting.

    – justhalf
    May 16 at 14:55






  • 1





    Since OP is using Comparator.comparing(...) the actual comparator will always compare -1 to -1, meaning all elements are equal. So the contract is not violated.

    – SamYonnou
    May 16 at 16:41











  • @SamYonnou Good catch. Updated my answer

    – Michael
    May 16 at 16:46


















4














You can make a list of pairs :



[3.0, 5.0]
[1.0, 0.9]
[2.0, 10.4]


Then sort this list of pairs by the first value of each array :



[1.0, 0.9]
[2.0, 10.4]
[3.0, 5.0]


Here is the code :



List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
List<Double> order = Arrays.asList(3.0, 1.0, 2.0);

List<Double[]> pairs = new ArrayList<>();
for (int i = 0; i < nums.size(); i++)
pairs.add(new Double[] order.get(i), nums.get(i));


pairs.sort(Comparator.comparing(pair -> pair[0]));

for (Double[] pair : pairs)
System.out.print(pair[1] + " ");



Output :



0.9 10.4 5.0 





share|improve this answer






























    2














    Update



    List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
    List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
    Map<Double,Double> numToOrder = new HashMap<>();
    for (int i = 0; i < nums.size(); ++i)
    numToOrder.put(nums.get(i), order.get(i));

    nums.sort(Comparator.comparing(num -> numToOrder.get(num)));
    System.out.println(nums);


    Original (wrong) answer



    (nums is modified in place, and the lambda returning key returns wrong results)



    List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
    List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
    nums.sort(Comparator.comparing(num -> order.get(nums.indexOf(num))));
    System.out.println(nums);





    share|improve this answer




















    • 2





      Results in [0.9, 5.0, 10.4], which is wrong

      – Michael
      May 16 at 10:07


















    1














    The Comparator you are supplying calls indexOf for every num passed.
    The returned values are -1 on all calls, so the order is preserverd as-is.



    You need to sort natural.



    Sorting by another list of Double should be possible, but unnecessarily complicated, it would be simpler to provide a custom Object which sorts as desired.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56165647%2fjava-comparator-comparing-not-comparing%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      17














      You are sorting the numbers by their position in the order list, but none of the numbers occur in the order list. In this case, indexOf will return -1 for everything, meaning everything is equal to everything else. In such a case, the resulting sort order is unspecified - though you may realistically assume that it would not change.






      share|improve this answer

























      • Oh, so I got it all wrong.. how then do I sort nums by order?

        – shakedzy
        May 16 at 9:56











      • @shakedzy I don't know what you mean by "sort nums by order"

        – Michael
        May 16 at 9:56











      • @Michael I believe using order as the keys for sorting.

        – justhalf
        May 16 at 14:55






      • 1





        Since OP is using Comparator.comparing(...) the actual comparator will always compare -1 to -1, meaning all elements are equal. So the contract is not violated.

        – SamYonnou
        May 16 at 16:41











      • @SamYonnou Good catch. Updated my answer

        – Michael
        May 16 at 16:46















      17














      You are sorting the numbers by their position in the order list, but none of the numbers occur in the order list. In this case, indexOf will return -1 for everything, meaning everything is equal to everything else. In such a case, the resulting sort order is unspecified - though you may realistically assume that it would not change.






      share|improve this answer

























      • Oh, so I got it all wrong.. how then do I sort nums by order?

        – shakedzy
        May 16 at 9:56











      • @shakedzy I don't know what you mean by "sort nums by order"

        – Michael
        May 16 at 9:56











      • @Michael I believe using order as the keys for sorting.

        – justhalf
        May 16 at 14:55






      • 1





        Since OP is using Comparator.comparing(...) the actual comparator will always compare -1 to -1, meaning all elements are equal. So the contract is not violated.

        – SamYonnou
        May 16 at 16:41











      • @SamYonnou Good catch. Updated my answer

        – Michael
        May 16 at 16:46













      17












      17








      17







      You are sorting the numbers by their position in the order list, but none of the numbers occur in the order list. In this case, indexOf will return -1 for everything, meaning everything is equal to everything else. In such a case, the resulting sort order is unspecified - though you may realistically assume that it would not change.






      share|improve this answer















      You are sorting the numbers by their position in the order list, but none of the numbers occur in the order list. In this case, indexOf will return -1 for everything, meaning everything is equal to everything else. In such a case, the resulting sort order is unspecified - though you may realistically assume that it would not change.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 16 at 16:46

























      answered May 16 at 9:53









      MichaelMichael

      22.9k83976




      22.9k83976












      • Oh, so I got it all wrong.. how then do I sort nums by order?

        – shakedzy
        May 16 at 9:56











      • @shakedzy I don't know what you mean by "sort nums by order"

        – Michael
        May 16 at 9:56











      • @Michael I believe using order as the keys for sorting.

        – justhalf
        May 16 at 14:55






      • 1





        Since OP is using Comparator.comparing(...) the actual comparator will always compare -1 to -1, meaning all elements are equal. So the contract is not violated.

        – SamYonnou
        May 16 at 16:41











      • @SamYonnou Good catch. Updated my answer

        – Michael
        May 16 at 16:46

















      • Oh, so I got it all wrong.. how then do I sort nums by order?

        – shakedzy
        May 16 at 9:56











      • @shakedzy I don't know what you mean by "sort nums by order"

        – Michael
        May 16 at 9:56











      • @Michael I believe using order as the keys for sorting.

        – justhalf
        May 16 at 14:55






      • 1





        Since OP is using Comparator.comparing(...) the actual comparator will always compare -1 to -1, meaning all elements are equal. So the contract is not violated.

        – SamYonnou
        May 16 at 16:41











      • @SamYonnou Good catch. Updated my answer

        – Michael
        May 16 at 16:46
















      Oh, so I got it all wrong.. how then do I sort nums by order?

      – shakedzy
      May 16 at 9:56





      Oh, so I got it all wrong.. how then do I sort nums by order?

      – shakedzy
      May 16 at 9:56













      @shakedzy I don't know what you mean by "sort nums by order"

      – Michael
      May 16 at 9:56





      @shakedzy I don't know what you mean by "sort nums by order"

      – Michael
      May 16 at 9:56













      @Michael I believe using order as the keys for sorting.

      – justhalf
      May 16 at 14:55





      @Michael I believe using order as the keys for sorting.

      – justhalf
      May 16 at 14:55




      1




      1





      Since OP is using Comparator.comparing(...) the actual comparator will always compare -1 to -1, meaning all elements are equal. So the contract is not violated.

      – SamYonnou
      May 16 at 16:41





      Since OP is using Comparator.comparing(...) the actual comparator will always compare -1 to -1, meaning all elements are equal. So the contract is not violated.

      – SamYonnou
      May 16 at 16:41













      @SamYonnou Good catch. Updated my answer

      – Michael
      May 16 at 16:46





      @SamYonnou Good catch. Updated my answer

      – Michael
      May 16 at 16:46













      4














      You can make a list of pairs :



      [3.0, 5.0]
      [1.0, 0.9]
      [2.0, 10.4]


      Then sort this list of pairs by the first value of each array :



      [1.0, 0.9]
      [2.0, 10.4]
      [3.0, 5.0]


      Here is the code :



      List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
      List<Double> order = Arrays.asList(3.0, 1.0, 2.0);

      List<Double[]> pairs = new ArrayList<>();
      for (int i = 0; i < nums.size(); i++)
      pairs.add(new Double[] order.get(i), nums.get(i));


      pairs.sort(Comparator.comparing(pair -> pair[0]));

      for (Double[] pair : pairs)
      System.out.print(pair[1] + " ");



      Output :



      0.9 10.4 5.0 





      share|improve this answer



























        4














        You can make a list of pairs :



        [3.0, 5.0]
        [1.0, 0.9]
        [2.0, 10.4]


        Then sort this list of pairs by the first value of each array :



        [1.0, 0.9]
        [2.0, 10.4]
        [3.0, 5.0]


        Here is the code :



        List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
        List<Double> order = Arrays.asList(3.0, 1.0, 2.0);

        List<Double[]> pairs = new ArrayList<>();
        for (int i = 0; i < nums.size(); i++)
        pairs.add(new Double[] order.get(i), nums.get(i));


        pairs.sort(Comparator.comparing(pair -> pair[0]));

        for (Double[] pair : pairs)
        System.out.print(pair[1] + " ");



        Output :



        0.9 10.4 5.0 





        share|improve this answer

























          4












          4








          4







          You can make a list of pairs :



          [3.0, 5.0]
          [1.0, 0.9]
          [2.0, 10.4]


          Then sort this list of pairs by the first value of each array :



          [1.0, 0.9]
          [2.0, 10.4]
          [3.0, 5.0]


          Here is the code :



          List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
          List<Double> order = Arrays.asList(3.0, 1.0, 2.0);

          List<Double[]> pairs = new ArrayList<>();
          for (int i = 0; i < nums.size(); i++)
          pairs.add(new Double[] order.get(i), nums.get(i));


          pairs.sort(Comparator.comparing(pair -> pair[0]));

          for (Double[] pair : pairs)
          System.out.print(pair[1] + " ");



          Output :



          0.9 10.4 5.0 





          share|improve this answer













          You can make a list of pairs :



          [3.0, 5.0]
          [1.0, 0.9]
          [2.0, 10.4]


          Then sort this list of pairs by the first value of each array :



          [1.0, 0.9]
          [2.0, 10.4]
          [3.0, 5.0]


          Here is the code :



          List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
          List<Double> order = Arrays.asList(3.0, 1.0, 2.0);

          List<Double[]> pairs = new ArrayList<>();
          for (int i = 0; i < nums.size(); i++)
          pairs.add(new Double[] order.get(i), nums.get(i));


          pairs.sort(Comparator.comparing(pair -> pair[0]));

          for (Double[] pair : pairs)
          System.out.print(pair[1] + " ");



          Output :



          0.9 10.4 5.0 






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 16 at 10:05









          Arnaud DenoyelleArnaud Denoyelle

          19.7k756105




          19.7k756105





















              2














              Update



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              Map<Double,Double> numToOrder = new HashMap<>();
              for (int i = 0; i < nums.size(); ++i)
              numToOrder.put(nums.get(i), order.get(i));

              nums.sort(Comparator.comparing(num -> numToOrder.get(num)));
              System.out.println(nums);


              Original (wrong) answer



              (nums is modified in place, and the lambda returning key returns wrong results)



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              nums.sort(Comparator.comparing(num -> order.get(nums.indexOf(num))));
              System.out.println(nums);





              share|improve this answer




















              • 2





                Results in [0.9, 5.0, 10.4], which is wrong

                – Michael
                May 16 at 10:07















              2














              Update



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              Map<Double,Double> numToOrder = new HashMap<>();
              for (int i = 0; i < nums.size(); ++i)
              numToOrder.put(nums.get(i), order.get(i));

              nums.sort(Comparator.comparing(num -> numToOrder.get(num)));
              System.out.println(nums);


              Original (wrong) answer



              (nums is modified in place, and the lambda returning key returns wrong results)



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              nums.sort(Comparator.comparing(num -> order.get(nums.indexOf(num))));
              System.out.println(nums);





              share|improve this answer




















              • 2





                Results in [0.9, 5.0, 10.4], which is wrong

                – Michael
                May 16 at 10:07













              2












              2








              2







              Update



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              Map<Double,Double> numToOrder = new HashMap<>();
              for (int i = 0; i < nums.size(); ++i)
              numToOrder.put(nums.get(i), order.get(i));

              nums.sort(Comparator.comparing(num -> numToOrder.get(num)));
              System.out.println(nums);


              Original (wrong) answer



              (nums is modified in place, and the lambda returning key returns wrong results)



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              nums.sort(Comparator.comparing(num -> order.get(nums.indexOf(num))));
              System.out.println(nums);





              share|improve this answer















              Update



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              Map<Double,Double> numToOrder = new HashMap<>();
              for (int i = 0; i < nums.size(); ++i)
              numToOrder.put(nums.get(i), order.get(i));

              nums.sort(Comparator.comparing(num -> numToOrder.get(num)));
              System.out.println(nums);


              Original (wrong) answer



              (nums is modified in place, and the lambda returning key returns wrong results)



              List<Double> nums = Arrays.asList(5.0, 0.9, 10.4);
              List<Double> order = Arrays.asList(3.0, 1.0, 2.0);
              nums.sort(Comparator.comparing(num -> order.get(nums.indexOf(num))));
              System.out.println(nums);






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 16 at 10:19

























              answered May 16 at 10:01









              LesiakLesiak

              2,75411127




              2,75411127







              • 2





                Results in [0.9, 5.0, 10.4], which is wrong

                – Michael
                May 16 at 10:07












              • 2





                Results in [0.9, 5.0, 10.4], which is wrong

                – Michael
                May 16 at 10:07







              2




              2





              Results in [0.9, 5.0, 10.4], which is wrong

              – Michael
              May 16 at 10:07





              Results in [0.9, 5.0, 10.4], which is wrong

              – Michael
              May 16 at 10:07











              1














              The Comparator you are supplying calls indexOf for every num passed.
              The returned values are -1 on all calls, so the order is preserverd as-is.



              You need to sort natural.



              Sorting by another list of Double should be possible, but unnecessarily complicated, it would be simpler to provide a custom Object which sorts as desired.






              share|improve this answer



























                1














                The Comparator you are supplying calls indexOf for every num passed.
                The returned values are -1 on all calls, so the order is preserverd as-is.



                You need to sort natural.



                Sorting by another list of Double should be possible, but unnecessarily complicated, it would be simpler to provide a custom Object which sorts as desired.






                share|improve this answer

























                  1












                  1








                  1







                  The Comparator you are supplying calls indexOf for every num passed.
                  The returned values are -1 on all calls, so the order is preserverd as-is.



                  You need to sort natural.



                  Sorting by another list of Double should be possible, but unnecessarily complicated, it would be simpler to provide a custom Object which sorts as desired.






                  share|improve this answer













                  The Comparator you are supplying calls indexOf for every num passed.
                  The returned values are -1 on all calls, so the order is preserverd as-is.



                  You need to sort natural.



                  Sorting by another list of Double should be possible, but unnecessarily complicated, it would be simpler to provide a custom Object which sorts as desired.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 16 at 9:53









                  Stefan HelmerichsStefan Helmerichs

                  356415




                  356415



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56165647%2fjava-comparator-comparing-not-comparing%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                      Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                      Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림