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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:26:36+00:00 2026-05-18T07:26:36+00:00

Hi I have written this code that with output you can get that .remove()

  • 0

Hi
I have written this code that with output you can get that .remove() method doesn’t work. a, b, c, and d are some Points Objects that have x and y members.

Here are a and b and c and d values, which in the if statement must be deleted for upper but it doesn’t.

X :59  Y: 143
X :165  Y: 140
X :59  Y: 143
X :165  Y: 140


   System.out.println(upper.toString());
        for(int i =0;i<upper.size();i++)

            if(upper.get(i)==a||upper.get(i)==b||upper.get(i)==c||upper.get(i)==d){
                upper.remove(i);

            }
        for(int i =0;i<lower.size();i++)

            if(lower.get(i)==a||lower.get(i)==b||lower.get(i)==c||lower.get(i)==d){
                upper.remove(i);
            }



        System.out.println(upper.toString());
        System.out.println(lower.toString());


   first println : [X :108  Y: 89, X :165  Y: 140]

   second println: [X :108  Y: 89, X :165  Y: 140]

   third println :  [X :105  Y: 191]
  • 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-18T07:26:37+00:00Added an answer on May 18, 2026 at 7:26 am

    If I’m reading your question right, you’re assuming that == will compare the properties of two objects. It doesn’t, that’s what equals does. == tells you whether two references are to the same object instance, not to equivalent ones.

    So for example:

    public class Foo {
        public Foo(int x, int y) {
            this.x = x;
            this.y = y;
        }
    
        @override
        public boolean equals(Object other) {
            Foo otherFoo;
    
            if (other == null || !(other instanceof Foo)) { // or you might be more restrictive
                return false;
            }
    
            otherFoo = (Foo)other);
            return otherFoo.x == this.x && otherFoo.y == this.y;
        }
    
        @override
        public int hashCode() {
            // ...appropriate implementation of hashCode...
        }
    }
    
    Foo a = new Foo(0, 0);
    Foo b = new Foo(0, 0);
    System.out.println(a == b);      // "false"
    System.out.println(a.equals(b)); // "true"
    

    Separately: Consider what happens when you have two consequtive matching objects in the ArrayList that you have to remove. Say they’re at indexes 8 and 9 in the list. So when i == 8, you remove the item at index 8, and the one that used to be at 9 is now at 8. But then you increment i in the for loop and continue with the new item at index 9, leaving the second one untouched. If you want to modify the list while you’re looping through it, consider looping backward to avoid that, or using an Iterator.

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

Sidebar

Related Questions

I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can
I have written some code that pulls info from a plist file and does
I have written some code in Java that will decode a SHOUTcast stream and
I have written a Windows service that spawns a separate process. This process creates
I have a dll that was written in c++, I need to use this
I have an existing application that is written in C++ for Windows. This application
I have written a code that maps to a shared memory location,so that the
I have written this piece of code: namespace { void SkipWhiteSpace(const char *&s) {
I have always written regexes like this <A HREF=([^]*) TARGET=_blank>([^<]*)</A> but I just learned
This is what I have written: if ((lstProperty[i].PropertyIdentifier as string).CompareTo(Name) == 0) Resharper put

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.