What's the difference b/w next() and hasNext()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2014 06:53 AM
- 32,268 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2014 07:15 AM
hasNext() either returns true or false while next() will actually iterate to the record.
So I could do:
gr.query();
if (gr.next()) {
gr.field = 'value';
gr.update();
}
but this won't update anything:
gr.query();
if (gr.hasNext()) {
gr.field = 'value';
gr.update();
}
So if there are one or more records contained in your gr set, hasNext() will return true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2014 07:28 AM
Hi Brad, in 2nd scenario, gr doesn't iterate to the actual record? if there is only one match, what is contained in the gr when using hasNext?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2023 05:12 AM
When I was try with above code in nest() if I got the updated record but not updated in case of hasNext().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 02:15 AM
hasNext() : hasNext() method returns true if iterator have more elements.
next() : next() method returns the next element and also moves to the next element.