Let's see this example C# code:
List<int> numbers = new List<int>() { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int numCount = numbers.Where(n => n < 3 || n > 7).Count();
I'm insterested in cloesest equivalent in Java, obviously without need to write fancy for/foreach loops to iterate in collection.
As far as I know, there is no exact linq equivalnet in Java, however I'm still beginner in Java programming, so is there anything you could recommend for me? I'm actually looking for most compact and elegant way to achieve the same result in Java
[added] So, thanks for all reponses. However, I need to use it on Android and it seem I can't. Is there any solution for that?
(sorry it it's duplicate)
[added] Have anybody tried this? http://sourceforge.net/projects/streamsupport/
Android is based on Linux Kernel so it's definitely possible to compile & run C/C++ programs on Android. C is quite cross-platform , so a C Program written in Windows can Run on Linux ( and android ) and vice versa.
SoloLearn. SoloLearn is one of the most popular apps to learn C++, Java, Python, SQL, CSS, HTML, C# etc. and has a largest collection of FREE code learning content.
The official language for Android development is Java. Large parts of Android are written in Java and its APIs are designed to be called primarily from Java. It is possible to develop C and C++ app using the Android Native Development Kit (NDK), however it isn't something that Google promotes.
Though Java is a good language, C++ has quite a few more advantages for Android mobile development. C++ helps to include lower memory footprint as it has no garbage collection. C++ can compile all C programs virtually allowing the developer to reuse C software. On the other hand, Java programs run faster than C++.
In Java8:
Arrays.stream(numbers).filter(n -> n < 3 || n > 7).count();
In response to your requirement for android, check out lambdaj: https://code.google.com/p/lambdaj/ It is compatible for android - although the syntax is different. You'll have to look at the documentation as i've never used it. You could also check out https://github.com/wagnerandrade/coollection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With