871

What is Java equivalent for LINQ?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Ahmed Atia
  • 17,848
  • 25
  • 91
  • 133
  • 1
    Also for Scala w/ full LINQ API: https://github.com/nicholas22/propelS – Scooterville Jun 09 '12 at 21:26
  • If you wish to make something similar to Linq, but on Android, here's a nice solution: http://www.slideshare.net/droidcon/green-dao http://greendao-orm.com/ – android developer Feb 18 '14 at 08:38
  • 5
    @craastad As a .NET guy now mostly stuck in Java world, I feel your pain. You should try Scala though -- first class functions / closures, for comprehensions (not the same as LINQ's query syntax, but useful in many of the same situations), a unified type system, type inference, some convenient workarounds for generic type-erasure ... all running on the JVM, interoperating with Java. Plus a bunch of other functional goodness like pattern matching, Option type, etc. – Tim Goodman Mar 24 '14 at 17:55

34 Answers34

844

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

:-)

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
AgileJon
  • 53,070
  • 5
  • 41
  • 38
  • 9
    is there something in the plan? integrated into the language? IS ther a JCP number? etc etc. – Cheeso Aug 01 '09 at 18:58
  • 6
    Very true, although a big part of what makes LINQ sooo nice is how deeply it is integrated into the language and compiler – AgileJon Aug 01 '09 at 18:59
  • @AgileJon - I don't understand your answer. What's very true? I wasn't being rhetorical with any of my questions. – Cheeso Aug 01 '09 at 19:24
  • 11
    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 Aug 01 '09 at 23:14
  • JaQu is the LINQ equivalent for Java. It was developed for H2, but should work for all databases since it uses JDBC. See my answer below. – Basil Musa Jun 02 '11 at 21:51
  • 3
    [JSR-335](http://www.jcp.org/en/jsr/proposalDetails?id=335) due in 2012, see my answer below. – Brett Ryan Sep 27 '11 at 11:33
  • 1
    There is nothing like LINQ for Java. java language does not have extension methods. unless java provides native language support for extension methods, real LINQ kind of usability is not possible. – Mahes Sep 30 '11 at 18:24
  • 12
    This is not correct. See: http://stackoverflow.com/questions/10879761/is-there-a-java-equivalent-for-linq/10879784 – Scooterville Jun 04 '12 at 10:26
  • 1
    While this was and still is correct it should be noted that Lambdas were planned for JDK7 before this question was raised and are one of the core components of JDK8. [See my answer for more details](http://stackoverflow.com/questions/1217228/what-is-the-java-equivalent-for-linq/6790067#6790067). – Brett Ryan Nov 29 '12 at 05:04
  • 1
    EL 3 (AKA JSR-341 http://jcp.org/en/jsr/detail?id=341) will have its equivalent to LINQ: https://java.net/projects/el-spec/pages/CollectionOperations – Victor Apr 24 '13 at 16:21
  • 25
    LINQ is an specification, not an implementation... Lambda expressions is a part of LINQ. All projects trying to port LINQ to Java are implementations for a concrete scenario (SQL, Objects...) but does not covr the main goal of LINQ: Integrate the Language Query in the code. Due to this, there is no real alternative nor initative, for now, that can be considered as an alternative. – sesispla Apr 28 '13 at 10:24
  • 4
    @nterry A purely subjective and opinionated comment intended to spike an unjust debate. – Brett Ryan Jun 15 '16 at 03:57
  • 2
    @BrettRyan Perhaps, but its objectively true that Java has nothing like it. – Nicholas Terry Jun 15 '16 at 22:52
  • 2
    LINQ no, but lambdas yes. In my experience the seasoned C# developers prefer the C# lambdas over LINQ, which implicitly does not make the language infinitely better. The compiler will convert query syntax into method syntax. – Brett Ryan Jun 16 '16 at 02:42
  • Please update the answer to link to https://stackoverflow.com/questions/31381992/java-equivalent-of-where-clause-in-c-sharp-linq – Fandi Susanto Nov 15 '17 at 05:34
  • Just have a look at this one: http://www.jinq.org/ – zsubzwary Nov 22 '18 at 00:16
156

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();
19WAS85
  • 2,853
  • 1
  • 20
  • 19
  • 7
    String for column name, which means compiler and IDE autocomplete won't help against typoes and refactoring is hard. Any plans to change that? – Liz Av Jan 28 '14 at 14:25
  • 2
    Hi, Ekevoo. I think that it will be awsome and I tryed to do that sometime. But at this moment, with Java 8, the Coollection is a deprecated lib. Maybe it's useful to oldest projects... What do you think? – 19WAS85 Apr 30 '14 at 16:25
  • 1
    @WagnerAndrade Last commit is 5-6 years ago. I'm assuming the functionality was largely replaced by Java 8? Also, very cool name :) – Honinbo Shusaku Sep 22 '16 at 13:36
148

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.

Brett Ryan
  • 26,937
  • 30
  • 128
  • 163
  • Weren't lambdas also scheduled to be in Java 7? What happened to that? – BlueRaja - Danny Pflughoeft Oct 11 '11 at 18:12
  • 7
    Oracle bought Sun (tongue in cheek). Java 7 was taking far too long (5 years) so lambdas missed the short-list, this was rather disappointing to the masses. That being said Oracle does look like it's picking up the ball and I think we're scheduled for Java 8 October next year. – Brett Ryan Oct 11 '11 at 23:21
  • 1
    Note that the [State of the Lambda](http://cr.openjdk.java.net/~briangoetz/lambda/sotc3.html) has been updated once again which now covers streams, internal iteration, short-circuiting and constructor references. I advise you all to read the new document. – Brett Ryan Nov 29 '12 at 03:37
  • Note [the release has been pushed to March 2014](http://openjdk.java.net/projects/jdk8/), reasons are covered on the [jdk8-dev](http://mail.openjdk.java.net/pipermail/jdk8-dev/2013-April/002336.html) mailing list and more extensively on [Mark Reinhold’s blog](http://mreinhold.org/blog/secure-the-train). – Brett Ryan Apr 24 '13 at 04:46
  • 7
    Lambda expressions are a little part of LINQ. – sesispla Apr 28 '13 at 10:26
  • 4
    @NeWNeO, if you're referring to the query language in C# then yes, nothing like this is coming to Java, however in my experience most seasoned C# developers prefer lambda syntax over the query language. However if you are referring to LINQ-to-Entities for example then you will find that lambdas in java will enable this and more. There is a lot more coming to Java 8 to enable this, such as [defender methods](http://cr.openjdk.java.net/~briangoetz/lambda/Defender%20Methods%20v4.pdf). – Brett Ryan Jun 23 '13 at 20:50
119

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mario Fusco
  • 13,548
  • 3
  • 28
  • 37
  • 6
    This is nice, but it is a far cry from being about to build a query and execute it again sql, xml, collection, etc. – bytebender Jun 08 '11 at 23:40
  • why might i be getting java.lang.ExceptionInInitializerError when using lambdaj select on a custom class in my android project? – topwik Aug 20 '12 at 18:02
  • 1
    +1 this is really good for those of us who don't care about SQL/XML and only want easier access to collections. – ashes999 May 06 '14 at 21:20
107

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

itsmysterybox
  • 2,748
  • 3
  • 21
  • 26
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • github.com/TrigerSoft/jaque found this way and lets create Expression Trees. Combined with Java 8 Lambdas, any LINQ capacity can be implemented with same effort as in .Net. – Konstantin Triger Oct 02 '14 at 22:23
  • See this answer for a comparison: http://stackoverflow.com/questions/25989449/parsing-and-translating-java-8-lambda-expressions – Konstantin Triger Jan 31 '15 at 01:02
50

LINQ to Objects - JAVA 8 has added the Stream API which adds support for functional-style operations on streams of values:

Package java.util.stream

Java 8 Explained: Applying Lambdas to Java Collections

LINQ to SQL/NHibernate/etc. (database querying) - One option would be to use JINQ which also uses the new JAVA 8 features and was released on Feb 26, 2014 on Github: https://github.com/my2iu/Jinq

Jinq provides developers an easy and natural way to write database queries in Java. You can treat database data like normal Java objects stored in collections. You can iterate over them and filter them using normal Java commands, and all your code will be automatically translated into optimized database queries. Finally, LINQ-style queries are available for Java!

JINQ project site: http://www.jinq.org/

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
29

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.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Sadegh
  • 6,654
  • 4
  • 34
  • 44
  • 2
    Quaere looks like it provides a bit of what LINQ provides, but the question is for an 'equivalent' – AgileJon Aug 01 '09 at 19:03
  • 6
    So it's something *like* LINQ, if not a direct equivalent ? That at least sounds helpful – Brian Agnew Aug 01 '09 at 23:26
  • 3
    @AgileJon: If he really meant equivalent, he wouldn't have asked. He could have typed `from x in xs select x` and found out the answer (no). – kizzx2 Jan 11 '11 at 15:04
17

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
  • 21,824
  • 5
  • 78
  • 111
16

you can use scala, it is similar in syntax and it's actually probably more powerful than linq.

Erion
  • 644
  • 1
  • 6
  • 19
10

Now that Java 8 supports lambdas, it's possible to create Java APIs that closely resemble LINQ.

Jinq is one of these new LINQ-style libraries for Java.

I am the developer of this library. It is based on five years of research on using bytecode analysis to translate Java to database queries. Similar to how C#'s D-LINQ is a query layer that sits on top of the Entity Framework, Jinq is able to act as a query layer sitting on top of JPA or jOOQ. It has support for aggregation, groups, and subqueries. Even Erik Meijer (the creator of LINQ) has acknowledged Jinq.

Ming-Yee Iu
  • 844
  • 6
  • 5
9

As on 2014, I can finally say that LINQ is finally there in java 8.So no need to find an alternative of LINQ anymore.

Abhinab Kanrar
  • 1,532
  • 2
  • 20
  • 46
9

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
  • 101
  • 1
  • 2
8

Java LINQ to SQL implementation. Provides full language integration and larger feature set compared to .NET LINQ.

Konstantin Triger
  • 1,576
  • 14
  • 11
7

I tried guava-libraries from google. It has a FluentIterable which I think is close to LINQ. Also see FunctionalExplained.

List<String> parts = new ArrayList<String>();  // add parts to the collection.    
FluentIterable<Integer> partsStartingA = 
    FluentIterable.from(parts).filter(new Predicate<String>() {
        @Override
        public boolean apply(final String input) {
            return input.startsWith("a");
        }
    }).transform(new Function<String, Integer>() {
        @Override
        public Integer apply(final String input) {
            return input.length();
        }
    });

Seems to be an extensive library for Java. Certainly not as succinct as LINQ but looks interesting.

Jonathan
  • 20,053
  • 6
  • 63
  • 70
Madhan Ganesh
  • 2,273
  • 2
  • 24
  • 19
7

https://code.google.com/p/joquery/

Supports different possibilities,

Given collection,

Collection<Dto> testList = new ArrayList<>();

of type,

class Dto
{
    private int id;
    private String text;

    public int getId()
    {
        return id;
    }

    public int getText()
    {
        return text;
    }
}

Filter

Java 7

Filter<Dto> query = CQ.<Dto>filter(testList)
    .where()
    .property("id").eq().value(1);
Collection<Dto> filtered = query.list();

Java 8

Filter<Dto> query = CQ.<Dto>filter(testList)
    .where()
    .property(Dto::getId)
    .eq().value(1);
Collection<Dto> filtered = query.list();

Also,

Filter<Dto> query = CQ.<Dto>filter()
        .from(testList)
        .where()
        .property(Dto::getId).between().value(1).value(2)
        .and()
        .property(Dto::grtText).in().value(new string[]{"a","b"});

Sorting (also available for the Java 7)

Filter<Dto> query = CQ.<Dto>filter(testList)
        .orderBy()
        .property(Dto::getId)
        .property(Dto::getName)
    Collection<Dto> sorted = query.list();

Grouping (also available for the Java 7)

GroupQuery<Integer,Dto> query = CQ.<Dto,Dto>query(testList)
        .group()
        .groupBy(Dto::getId)
    Collection<Grouping<Integer,Dto>> grouped = query.list();

Joins (also available for the Java 7)

Given,

class LeftDto
{
    private int id;
    private String text;

    public int getId()
    {
        return id;
    }

    public int getText()
    {
        return text;
    }
}

class RightDto
{
    private int id;
    private int leftId;
    private String text;

    public int getId()
    {
        return id;
    }

    public int getLeftId()
        {
            return leftId;
        }

    public int getText()
    {
        return text;
    }
}

class JoinedDto
{
    private int leftId;
    private int rightId;
    private String text;

    public JoinedDto(int leftId,int rightId,String text)
    {
        this.leftId = leftId;
        this.rightId = rightId;
        this.text = text;
    }

    public int getLeftId()
    {
        return leftId;
    }

    public int getRightId()
        {
            return rightId;
        }

    public int getText()
    {
        return text;
    }
}

Collection<LeftDto> leftList = new ArrayList<>();

Collection<RightDto> rightList = new ArrayList<>();

Can be Joined like,

Collection<JoinedDto> results = CQ.<LeftDto, LeftDto>query().from(leftList)
                .<RightDto, JoinedDto>innerJoin(CQ.<RightDto, RightDto>query().from(rightList))
                .on(LeftFyo::getId, RightDto::getLeftId)
                .transformDirect(selection ->  new JoinedDto(selection.getLeft().getText()
                                                     , selection.getLeft().getId()
                                                     , selection.getRight().getId())
                                 )
                .list();

Expressions

Filter<Dto> query = CQ.<Dto>filter()
    .from(testList)
    .where()
    .exec(s -> s.getId() + 1).eq().value(2);
Low Flying Pelican
  • 5,974
  • 1
  • 32
  • 43
6

You can try out my library CollectionsQuery. It allows to run LINQ like queries over collections of objects. You have to pass predicate, just like in LINQ. If you are using java6/7 than you have to use old syntax with Interfaces:

List<String> names = Queryable.from(people)
                                    .filter(new Predicate<Person>() {
                                                public boolean filter(Person p) {
                                                    return p.age>20;
                                                }
                                            })
                                    .map   (new Converter<Person,String>() {
                                                public Integer convert(Person p) {
                                                    return p.name;
                                                }
                                            })
                                    .toList();

You can also use it in Java8, or in old java with RetroLambda and it's gradle plugin, then you will have new fancy syntax:

List<String> names = Queryable.from(people)
                                    .filter(p->p.age>20)
                                    .map   (p->p.name)
                                    .toList();

If you need to run DB queryes, than you can look on JINQ, as mentioned above, but it can't be back-ported by RetroLambda, doe to use of serialized lambdas.

Bogdan Mart
  • 460
  • 8
  • 19
4

It sounds like the Linq that everyone is talking about here is just LinqToObjects. Which I believe only offers functionality that can already be accomplished today in Java, but with really ugly syntax.

What I see as the real power of Linq in .Net is that lambda expressions can be used in a context requiring either a Delegate or an Expression and will then be compiled into the appropriate form. This is what allows things like LinqToSql (or anything other than LinqToObjects) to work, and allows them to have a syntax identical to LinqToObjects.

It looks like all of the projects referred to above are only offering the capabilities of LinqToObjects. Which makes me thing that LinqToSql-type functionality is not on the horizon for Java.

MarkPflug
  • 28,292
  • 8
  • 46
  • 54
4

For basic functional collections, Java 8 has it built in, most of the major non-Java JVM languages have it built in (Scala, Clojure, etc), and you can get add on libs for earlier Java versions.

For full language integrated access to a SQL database, Scala (runs on the JVM) has Slick

clay
  • 18,138
  • 28
  • 107
  • 192
4

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.

metator
  • 41
  • 1
  • Yup it's a JPA API. Far from LINQ, but better than nothing. And one can say it's based loosely on Hibernate Criteria API. See: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/querycriteria.html – Hendy Irawan Dec 28 '10 at 02:47
4

There's a very good library that you can use for this.

Located here: https://github.com/nicholas22/jpropel-light

Lambdas won't be available until Java 8 though, so using it is a bit different and doesn't feel as natural.

Moox
  • 1,122
  • 9
  • 23
3

For LINQ (LINQ to Objects), Java 8 will have something equivalent, see Project Lambda.

It has Enumerable's LINQ to Objects extensions like stuffs. But for more complicated LINQ things like Expression and ExpressionTree (these are needed for LINQ to SQL and other LINQ providers if they want provide something optimized and real), there is not any equivalent yet but maybe we will see that in future :)

But I don't think there will be anything like declaratives queries on Java in future.

Ebrahim Byagowi
  • 10,338
  • 4
  • 70
  • 81
2

There is no such feature in java. By using the other API you will get this feature. Like suppose we have a animal Object containing name and id. We have list object having animal objects. Now if we want to get the all the animal name which contains 'o' from list object. we can write the following query

from(animals).where("getName", contains("o")).all();

Above Query statement will list of the animals which contains 'o' alphabet in their name. More information please go through following blog. http://javaworldwide.blogspot.in/2012/09/linq-in-java.html

Vishnu
  • 51
  • 2
2

Check out tiny-q. (Note that you currently can't download it.)

Here's an example adapted the above link:

First we need a collection of some data, let's say a set of strings

String[] strings = { "bla", "mla", "bura", "bala", "mura", "buma" };

Now we want to select only the strings which start with "b":

Query<String> stringsStartingWithB = new Query<String>(strings).where(
    new Query.Func<String, Boolean>(){
        public Boolean run(String in) {
            return in.startsWith("b");
        }
    }
);

No actual data moved copied or anything like that, it will get processed as soon as you start iterating:

for(String string : stringsStartingWithB ) {
    System.out.println(string);
}
Sam
  • 40,644
  • 36
  • 176
  • 219
t90
  • 37
  • 1
1

An anonymous user mentioned another one, Diting:

Diting is a class library provides query capabilities on collections through chainable methods and anonymous interface like Linq in .NET. Unlike most of other collection library those are using static methods need iterate whole collection, Diting provides a core Enumerable class whitch contains deffered chainable methods to implement query on collection or array.

Supported Methods: any, cast, contact, contains, count, distinct, elementAt, except, first, firstOrDefault, groupBy, interset, join, last, lastOrDefault, ofType, orderBy, orderByDescending, reverse, select, selectMany, single, singleOrDefault, skip, skipWhile, take, takeWhile, toArray, toArrayList, union, where

Rup
  • 33,765
  • 9
  • 83
  • 112
1

Scala.Now i star read it , and found it like linq but more simple and more unreadable. but scala can run at linux,yes? csharp need mono.

GeminiYellow
  • 1,016
  • 2
  • 12
  • 34
  • 1
    Scala needs a Java runtime to run: it won't necessarily work on a bare Linux install either depending on what components you install. – Rup Mar 03 '14 at 14:00
  • @Rup there's **fully compliant** JRE for GNU/Linux, and Mono is **not a fully compliant** .NET implementation. – Display Name Aug 21 '15 at 17:19
  • @Sarge That wasn't my point, but Mono runs LINQ well enough doesn't it? Besides, there's now Microsoft's own [.Net Core for Linux](http://dotnet.github.io/core/getting-started/). – Rup Aug 21 '15 at 17:24
  • (GNU/)Linux is not the only platform besides Windows, and JRE exists for a wide variety of platforms. Mono doesn't fully implement everything, for example there's no WPF. – Display Name Aug 21 '15 at 17:37
1

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.

Basil Musa
  • 8,198
  • 6
  • 64
  • 63
1

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.

pistacchio
  • 56,889
  • 107
  • 278
  • 420
  • 1
    Groovy or jRuby would also be viable candidates, since they all have a much more functional nature. – cdeszaq Dec 20 '11 at 14:38
0

Not really a "Linq to SQL" equivalent for Java. but something close to it . Query DSL

kj007
  • 6,073
  • 4
  • 29
  • 47
KyelJmD
  • 4,682
  • 9
  • 54
  • 77
0

There is no equivalent to LINQ for Java. But there is some of the external API which is looks like LINQ such as https://github.com/nicholas22/jpropel-light, https://code.google.com/p/jaque/

It's me
  • 1,065
  • 6
  • 15
  • 30
0

HQL (Hibernate Query Language) is very similar to Linq in .Net

kj007
  • 6,073
  • 4
  • 29
  • 47
Khalil10
  • 69
  • 7
0

you can try this library: https://code.google.com/p/qood/

Here are some reasons to use it:

  1. lightweight: only 9 public interface/class to learn.
  2. query like SQL: support group-by, order-by, left join, formula,...etc.
  3. for big data: use File(QFS) instead of Heap Memory.
  4. try to solve Object-relational impedance mismatch.
schsu01
  • 1
  • 1
0

You can use Java Functional Utils to convert C#'s 101 LINQ examples that's compatible with Java 1.7 on Android.

mythz
  • 141,670
  • 29
  • 246
  • 390
0

Shameless self plug: you could always use https://github.com/amoerie/jstreams

Works on Java 6 and up, a perfect fit for Android development.

It looks a lot like Scala operators, lodash, C# LINQ, etc.

Moeri
  • 9,104
  • 5
  • 43
  • 56
0

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.

Nico
  • 1,554
  • 1
  • 23
  • 35
  • 1
    Sure it was pursued, just not under the name "Pizza". The generics from Pizza got merged into GJ, which then became the Java 1.3 reference compiler (though generics were hidden behind a flag until 1.5). In the meantime... the rest of the ideas, plus a few extra, became Scala. – Kevin Wright Aug 03 '12 at 15:38
  • Thanks for that info, of course Scala is a good point here. But these abilities where not integrated into the Java language. You could use the Scala language to implement the nice query code and use the resulting binary then from Java. – Nico Aug 03 '12 at 17:03
  • Also see ONGL at http://commons.apache.org/proper/commons-ognl/, which is in use and still being maintained. – Nico Oct 20 '13 at 14:01