What is the Java equivalent for LINQ? [closed]

There is nothing like LINQ for Java.

...

Edit

Now with Java 8 we are introduced to the Stream API, this is a similar kind of thing when dealing with collections, but it is not quite the same as Linq.

If it is an ORM you are looking for, like Entity Framework, then you can try Hibernate

:-)


There is an alternate solution, Coollection.

Coolection has not pretend to be the new lambda, however we're surrounded by old legacy Java projects where this lib will help. It's really simple to use and extend, covering only the most used actions of iteration over collections, like that:

from(people).where("name", eq("Arthur")).first();
from(people).where("age", lessThan(20)).all();
from(people).where("name", not(contains("Francine"))).all();

Lambdas are now available within Java 8 in the form of JSR-335 - Lambda Expressions for the JavaTM Programming Language

UPDATE: JDK8 has now been released which contains project lambda. It's worth grabbing a copy of Java 8 in Action currently still MEAP.

Have a read of Brian Goetz articles relating to lambdas for a decent understanding of how lambdas are implemented within JDK8 while also gaining an understanding of streams, internal iteration, short-circuiting and constructor references.. Also check out the JSR's above to get further examples.

I've written a blog on some of the advantages of using lambdas in JDK8 called The Power of the Arrow, also NetBeans 8 has great support for converting constructs to JDK8 which I've also blogged about Migrating to JDK 8 with NetBeans.


You can select the items in a collection (and much more) in a more readable way by using the lambdaj library

https://code.google.com/archive/p/lambdaj/

It has some advantages over the Quaere library because it doesn't use any magic string, it is completely type safe and in my opinion it offers a more readable DSL.


You won't find an equivalent of LINQ unless you use the javacc to create your own equivalent.

Until that day when someone finds a viable way to do so, there are some good alternatives, such as

  • jOOQ
  • JINQ
  • JaQue
  • JaQu
  • Linq4j
  • Quaere (No longer maintained)
  • QueryDSL
  • JSR-341