function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
srikanth admin 24srikanth admin 24 

what is Next and HasNext and its difference?

what is Next and HasNext  and its difference?
Vivek DeshmaneVivek Deshmane
Hi srikanth,


hasNext() will return true it iteration has more values and next() returns the next element in iteration
List<string> listX = new List<String> {'A','B','C'}; Iterator<String> iter = listX.iterator(); while(iter.hasNext()) system.debug(iter.next());

The above code just grabs a single instance of your Iterator object and allows you to process the values.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_list.htm#apex_System_List_iterator

Plese let me know if it helps you.
Best Regards,
-Vivek