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

  • SEARCH
  • Home
  • 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 8809189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:48:34+00:00 2026-06-14T02:48:34+00:00

What can I do with Iterator class? It says DeckIterator is not abstract and

  • 0

What can I do with Iterator class? It says “DeckIterator is not abstract and does not override abstract method remove() in java.util.Iterator”

import java.util.*;
import java.io.Serializable;

public class Deck implements Iterable<Card>, Serializable {

// The field for a List
private List<Card> deck;

/**
 * Constructor creates the list, initializes all the cards in the deck and
 * shuffles them
 */
public Deck() {

    deck = new ArrayList<Card>();

    for (Card.Rank r : Card.Rank.values()) {
        for (Card.Suit s : Card.Suit.values()) {
            deck.add(new Card(r, s));
        }
    }

    shuffle();

    // Converting to a LinkedList
    List<Card> list = new LinkedList<Card>();
    for (int i = 0; i < deck.size(); i++) {
        list.add(deck.get(i));
    }
    deck = list;
}

/**
 * Method to randomize the cards
 */
public void shuffle() {

    Collections.shuffle(deck);
}

/**
 * Method that removes the top card from the deck
 *
 * @return the top card
 */
public Card deal() {

    return deck.remove(0);
}

/**
 * Number of cards remaining in the deck
 *
 * @return number of cards in the deck
 */
public int size() {

    return deck.size();
}

/**
 * Reinitializes the deck.
 */
public void newDeck() {

    List<Card> newList = new LinkedList<Card>();
    for (int i = 0; i < deck.size(); i++) {
        newList.add(deck.get(i));
    }
    deck = newList;

}

      public Iterator<Card> iterator(){

           Iterator<Card> aDeck = deck.iterator();
            return aDeck;
        }

It says “DeckIterator is not abstract and does not override abstract method remove() in java.util.Iterator”

public class DeckIterator implements Iterator<Card> {

    public List<Card> reverseIterator(){


        List<Card> reverseList = new LinkedList<Card>();
        for(int i = deck.size()-1; i >= 0; i--){
            reverseList.add(deck.get(i));
        }

        return reverseList;
    }

}


public static void main(String[] args){

    Deck myDeck = new Deck();
    System.out.println("The card " + myDeck.deal() + " is not in the deck now");

    }
}
  • 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-14T02:48:35+00:00Added an answer on June 14, 2026 at 2:48 am

    Your method newDeck() should clear/empty the list prior to adding new entries. Or rather just reinitialise deck to a new List. In fact most (all?) of the code in the constructor should be moved to the newDeck() method, and the constructor can simply call that.

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

Sidebar

Related Questions

In Java I can do by using an Iterator and then using the .remove()
ArrayList's Iterator class ArrayList.Itr is private, so I can't subclass that guy. The things
With help in the question Fast and flexible iterator for abstract class I created
The java.lang.Iterator interface has 3 methods: hasNext , next and remove . In order
Suppose I have a function which can either take an iterable/iterator or a non-iterable
there is insert iterator in database template library or other library, Can someone tell
bool operator()(Iterator it1, Iterator it2) const { return (*it1 < *it2); } Can someone
I know I can loop through a list of strings like this: list<string>::iterator Iterator;
Is there a pythonic solution to drop n values from an iterator? You can
Is it possible to access the std::for_each iterator, so I can erase the current

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.