Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:13:43+00:00 2026-06-01T15:13:43+00:00

I have this simple code public String toString() { **Iterator it = list.iterator();** String

  • 0

I have this simple code

public String toString() {

   **Iterator it = list.iterator();**
   String s;

   while(it.hasNext()){

     s = s + " " + Integer.toString(it.next());

   }
   System.out.println(s);

 // IMPLEMENT THIS METHOD VIA AN ITERATOR

 // MAKE SURE THE OUTPUT PRODUCED BY THE METHOD
 // DISPLAYS THE LEAST SIGNIFICANT BIT TO THE RIGHT.

  }

At the line with asterisks, I get the following compilation error.

Error: incompatible types
  required: Iterator
  found:    java.util.Iterator<java.lang.Integer>

I already tried this,

**Iterator<Integer> it = list.iterator();**

I get, Error: type Iterator does not take parameters

EDIT *

I forgot to mention, I have my own implementation of the interface methods.

/*
   * Inner class to implement the iterator for the <code>BitList</code>.
   */
  private class BitListIterator implements Iterator {

    /*
     * A reference to the current <code>Node</code> in the iterator. 
     */
    private Node current = null;

    /*
     * The expected modification count variable.
     *  Needed for the "fast-fail" implementation of the iterator.
     */    
    private int expectedModCount = modCount;

    /*
     * Advances the iterator to the next element in the list.
     */
    public int next() {
      checkValid();

      if (current == null) {
        current = first ;
      } else {
        current = current.next ; // move the cursor forward
      }

      if (current == null)
        throw new NoSuchElementException() ;

      return current.value ;
    }

  /**
   * Inserts a new <code>int</code> value immediately before the next element that would be returned by <code>next()</code>.
   */    
    public void add(int newElement) {
      Node newNode;

      if (current == null) {
        first = new Node(newElement, first);
        current = first;
      } else {
        current.next = new Node(newElement, current.next);
        current = current.next;
      }

      modCount++ ;
      expectedModCount++ ;
    }

  /**
   * Indicates whether there is a next element in the list being traversed or not.
   */      
    public boolean hasNext() {
      return ((current == null) && (first != null)) ||
        ((current != null) && (current.next !=null));
    }

  /**
   * Checks whether this iterator remains valid, i.e. no concurrent modifications have been made on the list.
   */      
    private void checkValid() {
      if (expectedModCount != modCount)
        throw new ConcurrentModificationException();
    }
  } // end of BitListIterator class

So if import the package I get the following errors

Error: BitList.BitListIterator is not abstract and does not override abstract method remove() in java.util.Iterator

Error: next() in BitList.BitListIterator cannot implement next() in java.util.Iterator
  return type int is not compatible with java.lang.Object

I have jdk 1.7 and its in use.

Any ideas would certainly help.

Thank you,

Mjall2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:13:45+00:00Added an answer on June 1, 2026 at 3:13 pm

    I suspect you haven’t declared list with a type. Try this:

    private List<Integer> list = new ArrayList<Integer>();
    

    Also, the message suggests you’ve imported the wrong Iterator class, which can happen if you aren’t careful when using your IDE. Ensure import java.util.Iterator;, and no other import of an Iterator class, appears at the top of your java file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following test code: public static final String[] list = { apple,ball,cat,dog,egg,fan,girl,hat,igloo,jerk
I have this simple code to count punctuation in a string. ie there's 2
I have this code: public void Contacts(string domainToBeTested, string[] browserList, string timeOut, int numberOfBrowsers)
I have this code: public void AddNode(string Node) { try { treeView.Nodes.Add(Node); treeView.Refresh(); }
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
I have this sample code for async operations (copied from the interwebs) public class
I have this simple code but I can't figure for the life of me
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I have this simple code in my user_controller.rb file #listing all users def index
i have this simple code to load data from other php page using get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.