-
-
Save GulajavaMinistudio/6cf6ea3e77e9f4b0c220a8249cd55314 to your computer and use it in GitHub Desktop.
One month with Kotlin: lambda example
This file contains 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
// 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(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment