You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
Java
44 lines
1.5 KiB
Java
4 years ago
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
import static java.util.Comparator.comparingInt;
|
||
|
|
||
|
public class StreamProducts {
|
||
|
public static void main(String[] args) {
|
||
|
StreamProduct door = new StreamProduct(1, "Wooden Door", 35);
|
||
|
StreamProduct floorPanel = new StreamProduct(2, "Floor Panel", 25);
|
||
|
StreamProduct window = new StreamProduct(3, "Glass Window", 10);
|
||
|
|
||
|
List<StreamProduct> streamProducts = new ArrayList<>();
|
||
|
streamProducts.add(door);
|
||
|
streamProducts.add(floorPanel);
|
||
|
streamProducts.add(window);
|
||
|
streamProducts.add(floorPanel);
|
||
|
streamProducts.add(window);
|
||
|
|
||
|
namesOfLightProductsWeightSortedLoop(streamProducts);
|
||
|
namesOfLightProductsWeightSortedLoopStreamed(streamProducts);
|
||
|
}
|
||
|
|
||
|
private static void namesOfLightProductsWeightSortedLoopStreamed(List<StreamProduct> streamProducts) {
|
||
|
|
||
|
}
|
||
|
|
||
|
private static void namesOfLightProductsWeightSortedLoop(
|
||
|
List<StreamProduct> streamProducts) {
|
||
|
List<StreamProduct> lightStreamProducts = new ArrayList<>();
|
||
|
|
||
|
for (StreamProduct streamProduct : streamProducts) {
|
||
|
if (streamProduct.getWeight() < 30) {
|
||
|
lightStreamProducts.add(streamProduct);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
lightStreamProducts.sort(comparingInt(StreamProduct::getWeight));
|
||
|
|
||
|
for (StreamProduct streamProduct : lightStreamProducts) {
|
||
|
System.out.println(streamProduct.getName());
|
||
|
}
|
||
|
}
|
||
|
}
|