Created
March 29, 2018 09:52
-
-
Save zhoujinl/777214a3a3b7e0ec22f6f1f3878f5517 to your computer and use it in GitHub Desktop.
DescendingOrder java 1.8 stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
import java.util.stream.Collectors; | |
public class DescendingOrder { | |
public static int sortDesc(final int num) { | |
return Integer.parseInt(String.valueOf(num) | |
.chars() | |
.mapToObj(i -> String.valueOf(Character.getNumericValue(i))) | |
.sorted(Comparator.reverseOrder()) | |
.collect(Collectors.joining())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment