+ 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.

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