How it works...
We are applying the use() extension function provided by the standard library to execute a set of operations on the Cursor instance. use() can be invoked on any class that implements the Closeable interface. Internally, after executing the lambda block passed to it as an argument, use() automatically invokes the close() function on the object it was called on. Thanks to that, we can safely perform any operation on the Cursor instance and be sure that, even if some of them fail or result in throwing an exception, the cursor will eventually be closed.
Inside the use() function's scope, we are iterating the cursor with the while loop by moving it to the next row in each iteration. For each of the rows, we are using the getString() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access