Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the hasNext() and next() methods to enable this iteration. In case it is of use, String has two methods which may provide useful --
Complete the hasNext() and next() methods to enable this iteration. In case it is of use, String has two methods which may provide useful -- size() (returning the number of chars it contains) and charAt() (returning the character at the location passed as an argument).
package edu.uncc.cse; import java.util.Iterator; import java.util.NoSuchElementException; /** * A simple iterator class that can be used to access each character in a {@code String}. * */ public class CharacterIterator implements Iterator { /** The String whose characters will be returned by this Iterator. */ private String characterSource; /** The next character in the String which will be returned by the Iterator. */ private int cursor; /** * Create a new Iterator which can be used to go through the characters in this String. * * @param str Source of characters over which we will be iterating. */ public CharacterIterator(String str) { cursor = 0; characterSource = str; } /** Returns whether the iterator has a next object. */ public boolean hasNext() { } /** Returns the next object in the iterator. */ public Character next() throws NoSuchElementException { } public void remove() { throw new UnsupportedOperationException(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started