Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

These days it would be

    var lowNums = Arrays.stream(numbers).filter(n -> n < 5).toList();
2024's Java is also quite a bit better than 2013's Java.

Which still isn't as nice as LINQ, but this way we've painted the alternative in its best light, not in the light that makes C# look the best.



One of the unfortunate pieces missing from Java's streams is the ability to easily extend them with additional operators. In C# they are all extension methods for the IEnumerable interface so you can add your own methods into the chain but that's not possible in Java.


It is coming, it is called Gatherers, another approach, same result.


Good that there's a solution coming up but it's not as nice as C# IMO. Gatherers are way more verbose both in usage and especially in implementation. In C# they can be written as generator methods which is a very intuitive way to work with streams of data.


I'm a huge fan of Gatherers, lovely API!


i posted that example from a comment that linked to this repo https://github.com/mythz/clojure-linq-examples

my point was that laguange support for sql like sytax is part of what makes LINQ linq. Java niceties is not relevant.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: