Skip to content

Instantly share code, notes, and snippets.

@ademar111190
Last active January 14, 2018 20:03
Show Gist options
  • Save ademar111190/b4cd2ca19269975eeac5 to your computer and use it in GitHub Desktop.
Save ademar111190/b4cd2ca19269975eeac5 to your computer and use it in GitHub Desktop.
One month with Kotlin: lambda example
// Using Lambdas on Kotlin
val items = ArrayList<String>()
items.sortBy { item ->
item.length()
}
//or more implicity
items.sortBy { it.length() }
//------------------------------------------------------------------------------
// Using the nearest from Lambdas in Java 7
ArrayList<String> items = ArrayList();
Collections.sort(items, new Comparator<String>(){
@Override
public int compare(String s1, String s2) {
return s1.length() - s2.length();
}
});
@PospolitaNV
Copy link

// Using the nearest from Lambdas in Java 8 (there were no lambdas in Java 7)
List items = new ArrayList<>();
items.sort(Comparator.comparingInt(String::length));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment