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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:36:17+00:00 2026-06-04T05:36:17+00:00

I’m learning how to use ArrayLists and decided to try making an ArrayList. I

  • 0

I’m learning how to use ArrayLists and decided to try making an ArrayList. I have found that I can do:

ArrayList<Object> list = new ArrayList<Object>();
list.add("Hi");
list.add(new Integer(5), 9);

(And I realize that I can just add an int, and it will auto-box it)
The problem is that I cannot put a double or Double inside of the ArrayList at a specified index, which I can do with Integer. I’ve tried like this:

list.add(new Double(4)); // I just redid it, and this one works. 
list.add(45.6); // So does this one.
list.add(new Double(4), 6); // it's this one that doesn't.
list.add(43.6, 9); // doesn't work either

So Doubles do fit in an ArrayList, but you can’t specify the index they should be at. If you try, the error that results is:

no suitable method found for add(double, int)
    method java.util.ArrayList.add(int,java.lang.Object) is not applicable
      (actual argument double cannot be converted to int by method invocation conversion)
    method java.util.ArrayList.add(java.lang.Object) is not applicable
      (actual and formal argument lists differ in length)

Why won’t it allow a double (or a String) at a specified index, yet it allows an Integer?

Thanks, -AJ

  • 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-04T05:36:19+00:00Added an answer on June 4, 2026 at 5:36 am

    Take a closer look at the error being given. It’s saying you are invoking the add method with two arguments. In this particular case you are passing in a double and an int. That method clearly doesn’t exist, even with the generic type erasure.

    It seems like you really did intend to call the two argument add method. In that case, you have the arguments reversed. The first argument must be the index (position) in the list, while the second argument must be the element being added. Your example should then be:

    list.add(6, new Double(4));
    

    This would be why adding an integer at a specific position worked for you. According to the type-checker, it is technically correct. However, since the first argument was an integer, it interpreted it as the index, whereas you were expecting it to be added to the list.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.