36 lines
1.1 KiB
Java
36 lines
1.1 KiB
Java
package lambda;
|
|
|
|
import java.util.*;
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.Timer;
|
|
|
|
/**
|
|
* This program demonstrates the use of lambda expressions.
|
|
* @version 1.0 2015-05-12
|
|
* @author Cay Horstmann
|
|
*/
|
|
public class LambdaTest
|
|
{
|
|
public static void main(String[] args)
|
|
{
|
|
var 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));
|
|
|
|
var 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);
|
|
}
|
|
}
|