[英]How do I extract a Collection from an ExecutionResult in Java?
Given the following query: 给定以下查询:
CREATE (versionNode:Version {previousVersions: [4,3,2,1]})
RETURN versionNode.previousVersions AS versions
how can I end up with a Collection<Long>
from an ExecutionResult
? 我如何才能从
ExecutionResult
获得Collection<Long>
? AFAIK, the Node#getProperty()
method can only return primitive types, so I cannot use that. AFAIK,
Node#getProperty()
方法只能返回原始类型,所以我不能使用它。 Is it possible? 可能吗?
I found a solution. 我找到了解决方案。 This code made me realize it:
这段代码使我意识到了:
String cypher = "CREATE (versionNode:Version {previousVersions: [4,3,2,1]}) " +
"RETURN versionNode.previousVersions AS versions";
ExecutionResult result = new ExecutionEngine(db).execute(cypher);
System.out.println(result.iterator().next().get("versions").getClass());
this outputted the strange symbol: 这输出了奇怪的符号:
class [J
According to the Java docs for Class#getName()
it means the type of the object returned is a primitive long
array. 根据Java文档
Class#getName()
说法,这意味着返回的对象的类型是原始的long
数组。
So now I can do this and get my numbers returned into a collection: 因此,现在我可以执行此操作,并将我的数字返回到集合中:
Collection<Long> versionsCollection = new ArrayList<>();
long[] versions = (long[]) result.iterator().next().get("versions");
for (long v : versions) {
versionsCollection.add(v);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.