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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:47:25+00:00 2026-05-26T02:47:25+00:00

For example (and this is very simplified), suppose I have a class for every

  • 0

For example (and this is very simplified), suppose I have a class for every card in a deck of cards… e.g. a KingOfSpaces class, a QueenOfSpades class, a JackOfDiamonds class, etc. All of which that extend Card. There might be multiple instances of KingOfSpaces.

And I have an ArrayList<Card>, with 5 objects in it. How can I check to see if that ArrayList contains at least one AceOfDiamonds?

  • 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-26T02:47:26+00:00Added an answer on May 26, 2026 at 2:47 am

    Let’s start out by pointing out that using classes for this sort of differentiation is almost certainly a bad thing. I’d say that you probably need to make ‘Card’ be a bit more intelligent (i.e. having a getSuit() and getOrdinal() method).

    But, if you insist on doing it that way, iterate the array list (you can google that – it’s a pretty basic thing) and compare each entry in the list using the instanceof operator.

    You tagged this question as having to do with ‘reflection’, which doesn’t seem right. Are you sure you didn’t mean to flag it ‘homework’ ?

    OK – what the heck, here’s the code:

    List<Card> hand = ...;
    for(Card card : hand){
      if (card instanceof AceOfDiamonds) return true;
    }
    

    but please don’t set up your class hierarchy like that – it’s horrible design.

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

Sidebar

Related Questions

Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have this very simple example that I am using to learn structs in
Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
I have this existing schema where a schedule table looks like this (very simplified).
In this very simplified and minimized example click event handler has been defined for
I use Ext.form.ComboBox in very similar way as in this example: http://extjs.com/deploy/dev/examples/form/forum-search.html What annoys
This is a very basic example of what I am trying to implement in
This is a very generic 'best practice' question, but here's an example. Let's say
This SQL statement example is very close to what I think I need... update
This seems like a very simple and a very common problem. The simplest example

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.