Question: what is the difference between next() and hasnext() methods?
Answer: hasNext() : hasNext() method returns true if iterator have more elements. next() : next() method returns the next element and also moves cursor pointer to the next element. hasNext() - Returns true if the iteration has more elements.