Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8231219

Sorted method does not sort the Integer type List.

    XMLWordPrintable

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      I have List of Integer when I try to sort it with Stream (by using sorted() method) and collect the result in Set , it returns the incorrect sorted values in set.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a Integer List
      like List<Integer> list = Arrays.asList(3,4,1,7,9,10,6,8,12,33,22);
      and then sort this list using stream
      Set<Integer> setSort = list.stream().sorted().collect(Collectors.toSet());

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1, 3, 4, 6, 7, 8, 9, 10, 12, 22, 33
      ACTUAL -
      1, 33, 3, 4, 6, 22, 7, 8, 9, 10, 12

      ---------- BEGIN SOURCE ----------
      import java.util.Arrays;
      import java.util.List;
      import java.util.Set;
      import java.util.stream.Collectors;


      public class StreamInJava8 {

      public static void main(String[] args) {
      List<Integer> list = Arrays.asList(3,4,1,7,9,10,6,8,12,33,22);
      Set<Integer> setSort = list.stream().sorted().collect(Collectors.toSet());
      System.out.println(setSort);
      }

      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            psonal Pallavi Sonal (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: