After excecuting a query in sparql jena, I tried to get the query result as a list, so I used this:
res = ResultSetFormatter.toList(results);
but when I write this method before that method the variable res returns null.
ResultSetFormatter.out(System.out, results);
res = ResultSetFormatter.toList(results);
I don’t know what is the problem.
At a guess, I’d say
ResultSetFormatter.out(ResultSet)consumes theResultSet. So after this method has completed,ResultSetis empty.It’s somewhat comparable to how an
Iteratorworks: once you’ve iterated over all the elements, the iterator is empty.