forum

Home / DeveloperSection / Forums / Is ArrayList change its hashcode after insert the data?

Is ArrayList change its hashcode after insert the data?

Jayden Bell 1414 20-Dec-2015
I think,  the hashCode() of an object could be the same thing of the object address as in C++, so I expected the hashCode of the object remain the same before and after insert 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 a different value, so which means after insert a value, the new list object is a deep copy value of the original one?

Updated on 21-Dec-2015

Can you answer this question?


Answer

1 Answers

Liked By