Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

How is use of the word consistent helpful in fraud reports?

Answered: 1 week ago

Question

What are the values and risks of self-disclosing communication?

Answered: 1 week ago