Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static String[] sort(String[] arr) {
- // with lambda
- Arrays.sort(arr, (a, b) -> a.compareTo(b));
- // without lambda
- Arrays.sort(arr, new Comparator<String>() {
- public int compare(String a, String b) {
- return a.compareTo(b);
- }
- });
- return arr;
- }
- public static void main(String[] args) {
- // prints [apple, banana, blue, green, yellow]
- System.out.println(Arrays.asList(sort(new String[] { "banana", "apple", "yellow", "blue", "green" })));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement