LINQ 的 Java 等价物是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1217228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the Java equivalent for LINQ?
提问by Ahmed Atia
What is Java equivalent for LINQ?
LINQ 的 Java 等价物是什么?
采纳答案by AgileJon
There is nothing like LINQ for Java.
没有什么比 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.
现在在 Java 8 中我们引入了Stream API,这在处理集合时是类似的事情,但它与 Linq 不太一样。
If it is an ORM you are looking for, like Entity Framework, then you can try Hibernate
如果是你要找的ORM,比如Entity Framework,那么你可以试试Hibernate
:-)
:-)
回答by Sadegh
回答by Timo Westk?mper
There are many LINQ equivalents for Java, see herefor a comparison.
Java 有许多 LINQ 等价物,请参阅此处进行比较。
For a typesafe Quaere/LINQ style framework, consider using Querydsl. Querydsl supports JPA/Hibernate, JDO, SQL and Java Collections.
对于类型安全的 Quaere/LINQ 样式框架,请考虑使用Querydsl。Querydsl 支持 JPA/Hibernate、JDO、SQL 和 Java 集合。
I am the maintainer of Querydsl, so this answer is biased.
我是 Querydsl 的维护者,所以这个答案是有偏见的。
回答by Mario Fusco
You can select the items in a collection (and much more) in a more readable way by using the lambdaj library
您可以使用 lambdaj 库以更易读的方式选择集合(以及更多)中的项目
https://code.google.com/archive/p/lambdaj/
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.
它比 Quaere 库有一些优势,因为它不使用任何魔法字符串,它是完全类型安全的,并且在我看来它提供了一个更具可读性的 DSL。
回答by Konstantin Triger
Java LINQ to SQLimplementation. Provides full language integration and larger feature set compared to .NET LINQ.
Java LINQ to SQL实现。与 .NET LINQ 相比,提供完整的语言集成和更大的功能集。
回答by Emil Wcis?o
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.
请参阅SBQL4J。它是与 Java 集成的类型安全的强查询语言。允许编写复杂和多重嵌套查询。有很多操作符,Java 方法可以作为构造函数在查询中调用。查询被转换为纯 Java 代码(在运行时没有反射),因此执行速度非常快。
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.
编辑:嗯,到目前为止,SBQL4J 是 Java 语言的唯一扩展,它提供了类似于 LINQ 的查询功能。有一些有趣的项目,如 Quaere 和 JaQue,但它们只是 API,而不是在编译时具有强类型安全性的语法/语义扩展。
回答by 19WAS85
There is an alternate solution, Coollection.
有一个替代解决方案,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:
Coolection 并没有假装是新的 lambda,但是我们被旧的遗留 Java 项目所包围,这个库将提供帮助。它的使用和扩展非常简单,仅涵盖集合迭代中最常用的操作,如下所示:
from(people).where("name", eq("Arthur")).first();
from(people).where("age", lessThan(20)).all();
from(people).where("name", not(contains("Francine"))).all();
回答by metator
Just to add another alternative: Java 6 does have a solution for type-safe database queries using the javax.persistence.criteriapackage.
只是添加另一种选择:Java 6 确实有一个使用javax.persistence.criteria包的类型安全数据库查询的解决方案。
Though i must say that this is not really LINQ, because with LINQ you can query any IEnumerable.
虽然我必须说这不是真正的 LINQ,因为使用 LINQ,您可以查询任何 IEnumerable。
回答by Lukas Eder
回答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.
JaQu 是 Java 的 LINQ 等价物。虽然它是为 H2 数据库开发的,但它应该适用于任何数据库,因为它使用 JDBC。