java
public class Test {
public static void main(String[] args) {
List<Integer> sales = new ArrayList<>(Arrays.asList(12, 30, 22, 4, 9));
for (Integer sale : sales) {
if (sale % 3 == 0 ) {
System.out.println(sale);
}
}
sales
.stream()
.filter(e -> e % 3 == 0)
.forEach(System.out::println);
sales
.stream()
.filter(e -> e % 3 == 0)
.map(e -> "(" + e + ")")
.forEach(System.out::println);
}
}
Result; 1st and 2nd are the same. I put parentheses in the third. I feel like it looks refreshing.
java
12
30
9
12
30
9
(12)
(30)
(9)
Recommended Posts