Stream API in Java


Use the Stream API to efficiently work with collections and perform operations like filter, sort, and map.

Source Code

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        List myList = Arrays.asList("apple", "banana", "cherry");
        List result = myList.stream().filter(s -> s.startsWith("a")).collect(Collectors.toList());
        System.out.println(result);
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments