Lambda Expressions in Java 8 by Nguyen Van

Lambda Expressions in Java 8 by Nguyen Van

Author:Nguyen, Van [Nguyen, Van]
Language: eng
Format: azw3
Published: 2016-12-29T16:00:00+00:00


Sample Code

String[] friendList = {"Tuan", "Nam", "Lan"};

Arrays.sort(friendList,

(friend01, friend02) ->

Integer.compare(friend01.length(), friend02.length()));

System.out.print(Arrays.toString(friendList));

Output

[Lan, Nam, Tuan]

Multiple lines of code

If your code cannot be written in 1 line, it can be enclosed in {} and your code now should explicitly contain a return statement

Sample Code

String[] friendList = {"Tuan", "Nam", "Lan"};

Arrays.sort(friendList,

(String friend01, String friend02) ->

{

if (friend01.length() > friend02.length())

return -1;

else

return 0;

});



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.