A lambda expression is a short block of code that you can pass around like a value. Before lambdas, doing this required creating an anonymous inner class, which meant several lines of boilerplate for a single operation.
Here is an anonymous class versus a lambda:
// anonymous class
Comparator<String> comp = new Comparator<String>() {
public int compare(String a, String b) {
return a.length() - b.length();
}
};
// lambda
Comparator<String> comp = (a, b) -> a.length() - b.length();
The lambda version does the same thing in one line. The arrow -> separates parameters from the body. Java infers the parameter types from context, so you don't need to write them out.