-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaTest.java
More file actions
36 lines (32 loc) · 1.1 KB
/
LambdaTest.java
File metadata and controls
36 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package lambda;
import javax.swing.*;
import java.util.Arrays;
import java.util.Date;
/**
* This program demonstrates the use of lambda expressions.
*
* @author Cay Horstmann
* @version 1.0 2015-05-12
*/
public class LambdaTest {
public static void main(String[] args) {
String[] planets = new String[]{
"Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune"
};
System.out.println(Arrays.toString(planets));
System.out.println("Sorted in dictionary order:");
Arrays.sort(planets);
System.out.println(Arrays.toString(planets));
System.out.println("Sorted by length:");
Arrays.sort(planets, (first, second) ->
first.length() - second.length());
System.out.println(Arrays.toString(planets));
Timer timer = new Timer(1000, event ->
System.out.println("The time is " + new Date()));
timer.start();
// keep program running until user selects "Ok"
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
}
}