About 43,600 results
Open links in new tab
  1. java: Arrays.sort() with lambda expression - Stack Overflow

    I want to sort String elements in the array months by length using Arrays.sort method. I was told here, that it's possible to use lambda expressions instead of creating new class implementing Comparator. Did it exactly the same way, yet it doesn't work.

  2. Java Sorting with Lambda Expression - Stack Overflow

    Jun 26, 2020 · Lambda. Now since this question asks for a custom sort order, you need to provide a custom compare(a, b) method. Fortunately, there is an overloaded version of Array.sort that allows you to do exactly this by providing a lambda method. A lambda is simply an inline function. In this case, it provides the desired comparison logic for the sort.

  3. Sorting ArrayList with Lambda in Java 8 - Stack Overflow

    Jul 24, 2017 · In your case, you can sort it the same way as in Java 1.2: Collections.sort(list); // case sensitive Collections.sort(list, String.CASE_INSENSITIVE_ORDER); // case insensitive If you want to do it in Java 8 way:

  4. java - How to use a Java8 lambda to sort a stream in reverse order ...

    Feb 19, 2015 · I'm using java lambda to sort a list. how can I sort it in a reverse way? I saw this post, but I want to use java 8 lambda. Here is my code (I used * -1) as a hack Arrays.asList(files).stream()...

  5. java - Sorting multiple attribute with Lambda Expressions - Stack …

    Oct 25, 2015 · java: Arrays.sort() with lambda expression. 1. How to sort a list of class objects on one of its fields ...

  6. java - How to sort with condition in JAVA8 lambda - Stack Overflow

    Mar 3, 2017 · In this case, it might be simpler without streams: List<Test> result = new ArrayList<>(list); result.sort( … ); where you can use the comparator of kennytm’s answer in the place of … . – Holger

  7. java - Sort map by value using lambdas and streams - Stack …

    Mar 22, 2018 · I'm new to Java 8, not sure how to use streams and it's methods to sort. If I have map as below, how to sort this map by value to take only top 10 entries using Java 8. HashMap&lt;String, Integer&...

  8. Sort Int array using lambda java 8 - Stack Overflow

    Mar 5, 2020 · Just to understand Lambda better I have a array of integer like below - Integer[] arr = {13, 7, 6, 45, 21, 9, 2, 100}; I want to sort the array using Lambda function of Java 8.

  9. java - How to sort List of objects by some property - Stack Overflow

    JAVA 8 and Above Answer (Using Lambda Expressions) In Java 8, Lambda expressions were introduced to make this even easier! Instead of creating a Comparator() object with all of it's scaffolding, you can simplify it as follows: (Using your object as an example) Collections.sort(list, (ActiveAlarm a1, ActiveAlarm a2) -> a1.timeStarted-a2 ...

  10. java - Lambda Expressions Arrays.sort - Stack Overflow

    Dec 1, 2019 · I have a question regarding Arrays.sort in Java and how this works with a lambda expression. Arrays.sort(logs, (log1, log2) -> { ... either returns -1, 0, 1 } Could anyone explain to me how this lambda expression exactly works with respect to the return values? If more information is needed, let me know.

Refresh