Streams in Java
Streams are a way to process collections of data in a declarative way. They allow you to filter, transform, and aggregate data using a functional programming style.
Example code:
python
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
int sum = numbers.stream()
.filter(n -> n % 2 == 0)
.mapToInt(Integer::intValue)
.sum();
System.out.println("Sum of even numbers: " + sum);
No comments:
Post a Comment