Skip to content

Instantly share code, notes, and snippets.

@alexandreroman
Created November 24, 2022 12:46
Show Gist options
  • Save alexandreroman/15d4c4166aa338819ecd310ed863934e to your computer and use it in GitHub Desktop.
Save alexandreroman/15d4c4166aa338819ecd310ed863934e to your computer and use it in GitHub Desktop.
Lambda with java.util.List
package sandbox;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
var strList = List.of("Hello", "world", "my", "name", "is", "Duke");
System.out.println("List: " + strList);
var newStrList = strList.stream().filter(s -> s.length() > 4).collect(Collectors.toUnmodifiableList());
System.out.println("New list: " + newStrList);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment