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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:24:49+00:00 2026-06-02T08:24:49+00:00

Hello, can somebody explain to me why this block of code doesn’t work? ArrayList<Object>

  • 0

Hello, can somebody explain to me why this block of code doesn’t work?

ArrayList<Object> list = new ArrayList<Object>();
list.add(list);

HashMap<Object, Integer> map = new HashMap<Object, Integer>();
map.put(list, 1);

After I put list to map, it throws StackOverFlowError.

I know this code doesn’t make any sense, I just want to know why it’s not working.

Thanks!

Edit:

stacktrace:

Exception in thread "main" java.lang.StackOverflowError
    at java.util.ArrayList.get(Unknown Source)
    at java.util.AbstractList$Itr.next(Unknown Source)
    at java.util.AbstractList.hashCode(Unknown Source)
    at java.util.AbstractList.hashCode(Unknown Source)
    ...
  • 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-02T08:24:52+00:00Added an answer on June 2, 2026 at 8:24 am

    It happens because you are trying to calculate hash of an ArrayList which contains itself. ArrayList calculates its own hash by calculating hashes of all the objects it references. As it references itself, it will try to calculate its own hash over and over again causing the stack overflow.

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

Sidebar

Related Questions

enter code here hello, everyone, can somebody explain what is my problem in this
Hello Can somebody explain why second cout in func(char *p) doesn't work: #include <cstdlib>
Can any one explain why the output of this code is only 'hello' and
Hello can anybody solve this please I'm creating the object in the action class
we can see function generate() { this.a = 'hello'; } obj = new generate();
Hello Experts can somebody please indentify the problem with this server why this is
Hello I'm having a problem here. The code looks like this. private void Form3_Load(object
Hello I'm writting junit test how can I test this method .. this is
Hello is there somebody here who knows how to add temporary datas into a
Can somebody tell me how to make the work with IE9: I am trying

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.