Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java/Android best equivalent for C# linq [duplicate]

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/

like image 201
user1209216 Avatar asked Sep 18 '15 07:09

user1209216


People also ask

Is C good for Android?

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.

Which mobile app is best for C programming?

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.

Is Android written in Java or C?

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.

Which is better for Android development Java or C++?

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++.


1 Answers

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

like image 129
caesay Avatar answered Nov 08 '22 07:11

caesay