package com.gpcoder.lambda;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
class Product {
int id;
String name;
float price;
public Product(int id, String name, float price) {
super();
this.id = id;
this.name = name;
this.price = price;
}
}
public class LambdaExpression6 {
public static void main(String[] args) {
List<Product> list = new ArrayList<>();
list.add(new Product(1, "Samsung A5", 17000f));
list.add(new Product(3, "Iphone 6S", 65000f));
list.add(new Product(2, "Sony Xperia", 25000f));
list.add(new Product(4, "Nokia Lumia", 15000f));
list.add(new Product(5, "Redmi4 ", 26000f));
list.add(new Product(6, "Lenevo Vibe", 19000f));
// using lambda to filter data
Stream<Product> filtered_data = list.stream().filter(p -> p.price > 20000);
// using lambda to iterate through collection
filtered_data.forEach(product -> System.out.println(product.name + ": " + product.price));
}
}
When I research Lambda expression I see this code with super()
keywords. And I just know The super keyword in Java is a reference variable which is used to refer immediate parent class object. But in this code, the keyword super()
with no parameter and no parents class. So why we have super()
there.