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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:15:51+00:00 2026-06-13T13:15:51+00:00

I have some troubles in dealing with this search() function that i wrote. Well,

  • 0

I have some troubles in dealing with this “search()” function that i wrote. Well, i need to check if an object already exists in my stack. My object looks like this:

 Boat [mLeft=[0, 0, 0], boat=L, mRight=[0, C, V]]

And my stack is something like this:

  Boat [mLeft=[0, 0, 0], boat=L, mRight=[0, C, V]]
  Boat [mLeft=[0, 0, 0], boat=C, mRight=[L, 0, V]]
  Boat [mLeft=[0, 0, 0], boat=V, mRight=[L, C, 0]]
  Boat [mLeft=[0, 0, 0], boat=0, mRight=[L, C, V]]

And this is my “search” function:

  public boolean search(Boat b){
    boolean r=false;
    for(int i=0;i<btStack.size();i++)
    {
        if(btStack.elementAt(i).equals(b))
        {
            r = true;               
        }
    }
    return r;
}

This is never true…and i don’t have any idea why. Can you help?Thanks

  • 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-13T13:15:52+00:00Added an answer on June 13, 2026 at 1:15 pm

    Default equals behavior of object class compares equality based on references.You need to override equals in Boat class. With equals you should also override hashcode

    @Override
    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (!(obj instanceof Boat))
            return false;
    
        Boat b = (Boat)obj;
        return  b.someproperty==this.someproperty;//Assuming someproperty is primitive
    }
    

    References:

    1. Equals and Hash Code
    2. Overriding equals and hashCode in Java
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some troubles with this regular expression in javascript. That same regex works
I have some troubles mapping a JSON Array to RestKit. This is what the
I have some troubles with positioning my label/password field. With this code they both
I have some troubles installing air files that've been built with air2.0beta or air2.0beta2
I have some troubles to find the right loop to check if some values
I have some troubles with Doctrine integration into ZF. After simple redirect $this->redirector->setGotoSimple(asd); Doctrine
i have some troubles implementing this layout: http://deconcini.net/maurer-schneebacher/projekte/elisabethinum.html Basically i would like to display
I have some troubles with an array. I have one array that I want
I have some troubles re-writing this query to using joins instead of the two
I have some troubles in my Android app. I need to start an intent

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.