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 188469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:01:34+00:00 2026-05-11T16:01:34+00:00

OK here is my problem. I have a linked list of card objects. I

  • 0

OK here is my problem. I have a linked list of card objects.

I have the following method

  public void removeCard(Card card){
        cards.remove(card);

  }

if I create Card c = new Card(5,C); for example

and there is a card with the exact same values 2, and C in the linked list (cards).

If I call the method CardPile.remove(card)
I dont get any errors, but the element that’s equal to the parameter card is not removed.
Any ideas why this is not happening?

import java.util.LinkedList;

public class CardPile {

    final char [] suit = {'C','D','H','S'};
    final char [] rank = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};

    LinkedList<Card> cards;


    public CardPile(){
            cards = new LinkedList<Card>();
    }


    public void addCard(Card card){
            cards.addLast(card);
    }
    public void removeCard(Card card){
            cards.remove(card);

    }
    public void removeSpecial(Card card){
            LinkedList<Card> temp = new LinkedList<Card>();
            for(int i=0; i<cards.size(); i++){
                    if(cards.get(i).equals(card)){
                            temp.add(cards.get(i));

                    }
            }
            cards = temp;
    }

    public void listCards(){
            for(int i=0; i<cards.size(); i++){
                    System.out.print(cards.get(i).toString()+" ");
            }
            System.out.println();
    }

    public boolean isEmpty(){
            if(cards.size()==0)
                    return true;
            else
                    return false;
    }

    public Card drawCard(){
            return cards.removeLast();
    }

    public boolean hasCard(Card card){
            int index = 0;
            boolean contained = false;
            if(cards.size()==0){
                    System.out.println("error, cards size is 0");
                    return false;
            }
            else{
                    while(index<cards.size() && !contained){
                            if(cards.get(index).isEqual(card)){
                                    System.out.println("Card found");
                                    contained=true;
                            }
                            index++;
                    }
            }

            return contained;
    }
}
  • 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-05-11T16:01:35+00:00Added an answer on May 11, 2026 at 4:01 pm

    Probably they are not equal then.

    Check the equals() method on Card.

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

Sidebar

Related Questions

Here's my problem: I have do create a menu/list of actions (which would be
Here's my problem: I have a virtual method defined in a .h file that
I am trying to implement a linked-list in C++. Currently, I have the following
I have a problem either adding to or traversing a linked list. The main
My problem is deleting a node from linked list. I have two structs :
Okay, here is the problem. I have an unordered list with a bunch of
I have datagrid with list of MyPlayer objects linked to ItemsSource, there are ComboBoxes
I have a generic linked list implementation with a node struct containing a void*
I got a problem here, implementing a Sorted Doubly Linked List of first and
I am new to linked list in C and the problem I have is

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.