3 ms·
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 s
by svieira 2y ago
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.
- Rohansi 2y agoOne 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.
- pjmlp 2y agoIt is coming, it is called Gatherers, another approach, same result.
- svieira 2y agoI'm a huge fan of Gatherers, lovely API!
- Rohansi 2y agoGood 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.
- apwell23 2y agoi posted that example from a comment that linked to this repo https://github.com/mythz/clojure-linq-examples 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.