---
title: "Is  ArrayList change its hashcode after insert the data?"  
description: "Is  ArrayList change its hashcode after insert the data?"  
author: "Jayden Bell"  
published: 2015-12-20  
updated: 2015-12-21  
canonical: https://www.mindstick.com/forum/33761/is-arraylist-change-its-hashcode-after-insert-the-data  
category: "java"  
tags: ["java", "array list"]  
reading_time: 2 minutes  

---

# Is  ArrayList change its hashcode after insert the data?

I think, the hashCode() of an object could be the same thing of the object address as in [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus), so I expected the hashCode of the object remain the same before and after [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) the data.\

```
import java.util.ArrayList;import java.util.HashMap;import java.util.List;public class Hello {    public static void main(String[] args) {        List<Integer> a = new ArrayList<>(1024);        a.add(0, 1);        System.out.println(a.hashCode());        a.add(1, 2);        System.out.println(a.hashCode());    }}
```

but it seems it [output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) a different [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages), so which means after insert a value, the new list object is a [deep copy](https://www.mindstick.com/interview/33945/discuss-the-differences-between-deep-copy-and-shallow-copy-in-java-objects) value of the original one?

## Replies

### Reply by Anonymous User

hashCode isn't the object's address, but the calculated hash value of the object's content. Refer to javadoc for more information\
If you want to compare and check if it is the same object then you can use == operator, which checks the reference.\
According to Javadocs , the hashcode of a List will be calculated based on the individual objects hash code in it. So whenever you add an element to the List, this is going to affect the hashCode of the List directly.\


---

Original Source: https://www.mindstick.com/forum/33761/is-arraylist-change-its-hashcode-after-insert-the-data

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
