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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:27:27+00:00 2026-05-27T01:27:27+00:00

I have a mArraylist object,the Strange things happens after mArraylist add(object); here is my

  • 0

I have a mArraylist object,the Strange things happens after mArraylist add(object);
here is my source.why is aj1 equals aj2 in arraylist.It make me crazy! what’s wrong?

          /*get a mArraylist*/
           ArrayList<JSONObject> ajson;
           /*get an object that to be add.*/
        JSONObject jsonObject = new JSONObject();
    /*check result*/
        ArrayList<JSONObject> aj1 = new ArrayList<JSONObject>();
        aj1 = ajson;
        int size_outter = ajson.size();


        ArrayList<JSONObject> aj2 = new ArrayList<JSONObject>();
        ajson.add(jsonObject);
        aj2 = ajson;
        int size_inner = ajson.size();

    /*check aj1,aj2,eqauls*/
        if (aj1.equals(aj2))
        {
            System.out.println("aj1.equals(aj2)======true==");
        }

        System.out.println("aj1=ajson============size" + size_outter);
        System.out.println("aj2=ajson============size" + size_inner);

        System.out.println("aj1=============size" + aj1.size());
        System.out.println("aj2=============size" + aj2.size());



//the output is 
11-26 12:40:37.885: INFO/System.out(7214): aj1.equals(aj2)======true==
11-26 12:40:37.885: INFO/System.out(7214): aj1=ajson============size0
11-26 12:40:37.885: INFO/System.out(7214): aj2=ajson============size1
11-26 12:40:37.885: INFO/System.out(7214): aj1=============size1
11-26 12:40:37.885: INFO/System.out(7214): aj2=============size1

why aj1 equals aj2? but its size is not?
  • 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-27T01:27:28+00:00Added an answer on May 27, 2026 at 1:27 am

    aj1 and aj2 are 2 references to the same object (ajson), you did that when these 2 lines:

    aj1 = ajson;
    ...
    aj2 = ajson;
    

    as matter of the fact the size is the same:

    11-26 12:40:37.885: INFO/System.out(7214): aj1=============size1
    11-26 12:40:37.885: INFO/System.out(7214): aj2=============size1
    

    With this line:

    if (aj1.equals(aj2))
    

    you are comparing the same object.

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

Sidebar

Related Questions

I have a listView, populated with an ArrayList of object (xml parsing) and an
I have been trying to check my arraylist to see if an object already
I have added some values to drawPoints[][] and then made an ArrayList Object points
I am hitting a strange problem in relation to equals on an object transported
I have an arrayList of object Player. Player has field id, and score. suppose
I have a problem. I have an ArrayList of objects. Each object contains a
I have an ArrayList of object. The object contain attributes date and value .
I have an ArrayList of an object which has properties Object.name and Object.url .
I have an ArrayList of objects where each object contains a string 'word' and
I have a serializable object (ArrayList) within a Parcelable object. I am trying to

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.