What's the difference b/w next() and hasNext()?

jamesgo
Giga Contributor

if the query has only one match, will hasNext() return true?

11 REPLIES 11

Anurag Tripathi
Mega Patron

Hi,

hasNext() just checked whether the query has return records or not , just a boolean return.

next() actually does moves the pointer to the first to next record in the iteration.

 

 

-Anurag

Tanushree Maiti
Kilo Patron

next ()  - we use when iterate in a loop and moves to the next record.

              - Its return True (Boolean) - if successfully iterate to next record ( e.g post queried on GlideRecord)

             - Typically used under While condition.

 

hasNext() - we use when we want to check whether next record exists or not.

                     Its return True(Boolean) - Next record exists.

                     Use under IF condition.

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: