What is the Java equivalent for LINQ? [closed]

0 votes
asked Aug 1, 2009 by ahmed

What is Java equivalent for LINQ?

26 Answers

0 votes
answered Aug 1, 2009 by agilejon

There is nothing like LINQ for Java.

0 votes
answered Aug 1, 2009 by adinochestva

There is a project called quaere.

It's a Java framework which adds the ability to query collections.

Note: According to the author, the project is not maintained anymore.

0 votes
answered Aug 7, 2010 by metator

Just to add another alternative: Java 6 does have a solution for type-safe database queries using the javax.persistence.criteria package.

Though i must say that this is not really LINQ, because with LINQ you can query any IEnumerable.

0 votes
answered Aug 9, 2010 by lukas-eder

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

0 votes
answered Aug 12, 2010 by konstantin-triger

A C#-like solution is JaQue, which provides Expression Trees for Java Lambdas. On top of this can be implemented domain specific LINQ providers.

0 votes
answered Aug 24, 2010 by mario-fusco

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.

0 votes
answered Aug 29, 2010 by 19was85

I developed a alternate solution, Coollection. Is simple and focused on the most used actions of iteration over Collections.

Use like that:

  from(people).where("name", eq("Arthur")).first();
  from(people).where("age", lessThan(20)).all();
  from(people).where("name", not(contains("Francine"))).all();
0 votes
answered Jan 2, 2011 by basil-musa

JaQu is the LINQ equivalent for Java. Although it was developed for the H2 database, it should work for any database since it uses JDBC.

0 votes
answered Jan 17, 2011 by nico

There was the programming language Pizza (a Java extension) and you should have a look to it. - It uses the concept of "fluent interfaces" to query data in a declarative manner and that is in principle identical to LINQ w/o query expressions (http://en.wikipedia.org/wiki/Pizza_programming_language). But alas it was not pursued, but it would have been one way to get something similar to LINQ into Java.

0 votes
answered Jan 23, 2011 by pistacchio

Maybe not the answer you're hoping for, but if some part of you code need heavy work on collections (searching, sorting, filtering, transformations, analysis) you may take in consideration to write some classes in Clojure or Scala.

Because of their functional nature, working with collections is what they're best at. I don't have much experience with Scala, but with Clojure you'd probably find a more powerful Linq at your fingertips and once compiled, the classes you'd produce would integrate seamlessy with the rest of the code base.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...