Last active
August 3, 2025 17:59
-
-
Save tuldok89/b8f60b54726b3aecdb88b7726e04a9d9 to your computer and use it in GitHub Desktop.
Java Streams vs .NET LINQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| List<Person> people = new ArrayList<>(); | |
| people.add(new Person("Warren Buffett", 120)); | |
| people.add(new Person("Jeff Bezos", 150)); | |
| people.add(new Person("Bill Gates", 100)); | |
| people.add(new Person("Mark Zuckerberg", 50)); | |
| List<Person> hundredClub = people.stream() | |
| .filter(person -> person.billions >= 100) | |
| .sorted(Comparator.comparing(person -> person.name)) | |
| .collect(Collectors.toList()); | |
| hundredClub.forEach(person -> System.out.println(person.name)); | |
| } | |
| static class Person { | |
| private String name; | |
| private int billions; | |
| public Person(String name, int billions) { | |
| this.name = name; | |
| this.billions = billions; | |
| } | |
| public String getName() { | |
| return this.name; | |
| } | |
| public void setName(String name) { | |
| this.name = name; | |
| } | |
| public int getBillions() { | |
| return this.billions; | |
| } | |
| public void setBillions(int billions) { | |
| return this.billions; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class Main | |
| { | |
| public static void main(string[] args) | |
| { | |
| var people = new List<Person>(); | |
| people.Add(new Person("Warren Buffett", 120)); | |
| people.Add(new Person("Jeff Bezos", 150)); | |
| people.Add(new Person("Bill Gates", 100)); | |
| people.Add(new Person("Mark Zuckerberg", 50)); | |
| var hundredClub = people.Where(person => person.Billions >= 100) | |
| .Sort(person => person.Name) | |
| .ToList(); | |
| hundredClub.ForEach(person => Console.WriteLine(person.Name) | |
| } | |
| internal static class Person | |
| { | |
| public int Billions { get; set; } | |
| public string Name { get; set; } | |
| public Person(int billions, string name) | |
| { | |
| Billions = billions; | |
| Name = name; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| List<Person> people = new ArrayList<>(); | |
| people.add(new Person("Warren Buffett", 120)); | |
| people.add(new Person("Jeff Bezos", 150)); | |
| people.add(new Person("Bill Gates", 100)); | |
| people.add(new Person("Mark Zuckerberg", 50)); | |
| List<Person> hundredClub = people.stream() | |
| .filter(person -> person.billions >= 100) | |
| .sorted(Comparator.comparing(person -> person.name)) | |
| .collect(Collectors.toList()); | |
| hundredClub.forEach(person -> System.out.println(person.name)); | |
| } | |
| static class Person { | |
| String name; | |
| int billions; | |
| public Person(String name, int billions) { | |
| this.name = name; | |
| this.billions = billions; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment