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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:15:52+00:00 2026-06-17T21:15:52+00:00

I tried a code double temp=0; List list=new ArrayList(); list.add(1.1); temp+=list.get(0); //error occurs here

  • 0

I tried a code

double temp=0;
List list=new ArrayList();
list.add(1.1);
temp+=list.get(0); //error occurs here

Error that occurred is as follows

bad operand types for binary operator ‘+’

first type: double

second type: Object

What should I do to add the temp value and the double value in the list?

The programming language that I preferred is Java.

  • 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-17T21:15:52+00:00Added an answer on June 17, 2026 at 9:15 pm

    You should always use Generic type for your Collections type like List, ArrayList, so on, when programming in Java 1.5+.

    When you use a raw type List, then the method List.get(0) will always give you Object type, which you would need to do some casting to get it to work.

    So, either you can add a casting to Double in your current code, which is absolutely a bad idea.

    Or, you should use generic version of List as below: –

    List<Double> list=new ArrayList<Double>();
    list.add(1.1);
    

    Note that, the value 1.1 is a double, still it can be added directly, without the need to convert it to Double. This is because of the feature of Java called Auto Boxing.

    In Java, when you store a double value in a Double reference, then the double value is automatically boxed into Double. While in reverse case, it is called Unboxing, i.e. from Double to double.

    That is why, when you do: –

    temp+=list.get(0);
    

    the value of list.get(0) is of type Double. And since you are performing an operation with double primitive type, that vlaue is automatically boxed to double, and addition operation is performed.

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

Sidebar

Related Questions

I have tried to implement doubly linked list in C++. Here is the code,
I tried this code to open a file in Python: f = open("/Desktop/temp/myfile.txt","file1") It
I have this line of code: double seconds = new DateTime(2006,7,6,12,1,0,DateTimeKind.Local).Subtract(new DateTime(1970,1,1,0,0,0,DateTimeKind.Local).TotalSeconds; This was
In my application I have a Grid that is divided in two columns: instance_room[room_guid].Room_grid.ColumnDefinitions.Add(new
Here is some pseudo c++ code double var = 5.5; cout << var <<
I tried below code but as I run it gives a black screen image
i have tried this code to redirect a php page.but it s not working
I was practicing some programming problems and tried to code the popular reverse words
Iam running WAMP server and just enabled php_memcache extension and have tried the code
I was doing an assignment, tried simplifying code with same results. unsigned char x=5;

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.