Skip to content

Instantly share code, notes, and snippets.

@truongquoc
Last active October 17, 2023 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save truongquoc/fe7fb684c0af9f225a470aae5ec8d7e5 to your computer and use it in GitHub Desktop.
Save truongquoc/fe7fb684c0af9f225a470aae5ec8d7e5 to your computer and use it in GitHub Desktop.
Stream API
@Test
public void test() {
List<String> words = Arrays.asList("apple", "banana", "cherry", "date", "elderberry");
// Declare a Stream that filters words starting with the letter 'a'
Stream<String> filteredWords = words.stream().peek(System.out::println).filter(word -> word.startsWith("a"));
filteredWords.forEach(System.out::println);
boolean isValidate = filteredWords.count() > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment