views:

5915

answers:

11

What is Java equivalent for LINQ?

+19  A: 

There is nothing like LINQ for Java.

AgileJon
Yet. (oh why 10 chars...)
280Z28
is there something in the plan? integrated into the language? IS ther a JCP number? etc etc.
Cheeso
Very true, although a big part of what makes LINQ sooo nice is how deeply it is integrated into the language and compiler
AgileJon
@AgileJon - I don't understand your answer. What's very true? I wasn't being rhetorical with any of my questions.
Cheeso
Sorry, the 'very true' was meant for 280Z28. I don't know if there is a JCP for it. LINQ necessitated several changes to the C# language, given the speed the JCP works at I wouldn't hold my breath.
AgileJon
+12  A: 

there is a project called quaere

its a java framework which adds abilitiy to query collections

Adinochestva
Quaere looks like it provides a bit of what LINQ provides, but the question is for an 'equivalent'
AgileJon
So it's something *like* LINQ, if not a direct equivalent ? That at least sounds helpful
Brian Agnew
A: 

LINQ is syntactical sugar which must be implemented in the compiler. No such thing is currently being done as far as I know for javac or the Eclipse java compiler.

Hence, no LINQ.

Thorbjørn Ravn Andersen
LINQ is not syntactic sugar at all, I'm sorry, but you don't know what you're talking about. Method-chain LINQ particularly is just a way do functional programming in C#.
legenden
+1  A: 

There are many LINQ equivalents for Java, see here for a comparison.

For a typesafe Quaere/LINQ style framework, consider using Querydsl. Querydsl supports JPA/Hibernate, JDO, SQL and Java Collections.

I am the maintainer of Querydsl, so this answer is biased.

Timo Westkämper
+10  A: 

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

http://code.google.com/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.

Mario Fusco
+3  A: 

A more C#-like solution is JaQue. It has both: linq-to-object/xml functionality and a provider model with API very similar to MS LINQ. A simple JPA (Hibernate) provider is implemented. After Java will get closures, it will be elegant as well.

Konstantin Triger
+3  A: 

See SBQL4J. It's type-safe strong query language integrated with Java. Allows to write complicated and multiply nested queries. There is a lot of operators, Java methods can be invoked inside queries so as constructors. Queries are translated to pure Java code (there is no reflection at runtime) so execution is very fast.

EDIT: Well, so far SBQL4J it's the ONLY extension to Java language which gives query capabilities similar to LINQ. There are some interesting project like Quaere and JaQue but they are only API's, not syntax / semantics extension with strong type safety in compile time.

Emil Wcisło
A: 

Dont worry about LINQ, Microsoft themselves have moved ahead away from LINQ with the entity framework, which is basically hibernate or JPA.

mP
-1 as LINQ and Entity Framework are different things. Entity Framework is an ORM, while LINQ is a compiler-checked (type-safe) way to query objects in general, not just databases.
Marcel
@mP: I think you mean LINQ to SQL, not LINQ itself
Richard Ev
@MarcelI was referring to LINQ to SQL - the fact remains that it is sort of deprecated in favour of the Entity Framework as the preferred MS way to do ORM in dot net.
mP
@mP If I might, suggest you update your answer to reflect what you really meant and provide the appropriate reference that MS has made those decisions.
Lucas B
Take a look at the Entity Framework. Its functionality superceeds LINQ for SQL...They may be implementeddifferently but the goals are the same.
mP
@mP: The question is about LINQ in general, not LINQ to SQL. So, while your answer may be accurate with regards to LINQ to SQL, it's not true about LINQ in general.
cdmckay
With LINQ to SQL gone thats more than have the general use cases for LINQ...
mP
A: 

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();
Wagner Andrade
A: 

Try the open-source Ujorm ORM framework with a type-safe queries.

pop