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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:58:21+00:00 2026-06-10T15:58:21+00:00

I know that Double is a a wrapper class, and it wraps double number.

  • 0

I know that Double is a a wrapper class, and it wraps double number. Today, I have seen another main difference :

double a = 1.0;
double b = 1.0;
Double c = 1.0;
Double d = 1.0;
System.out.println(a == b);  // true
System.out.println(c == d);  // false

So strange with me !!!

So, if we use Double, each time, we must do something like this :

private static final double delta = 0.0001;
System.out.println(Math.abs(c-d) < delta); 

I cannot explain why Double make directly comparison wrong. Please explain for me.

  • 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-10T15:58:22+00:00Added an answer on June 10, 2026 at 3:58 pm

    c and d are technically two different objects and == operator compares only references.

    c.equals(d)
    

    is better as it compares values, not references. But still not ideal. Comparing floating-point values directly should always take some error (epsilon) into account (Math.abs(c - d) < epsilon).

    Note that:

    Integer c = 1;
    Integer d = 1;
    

    here comparison would yield true, but that’s more complicated (Integer internal caching, described in JavaDoc of Integer.valueOf()):

    This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.

    Why valueOf()? Because this method is implicitly used to implement autoboxing:

    Integer c = Integer.valueOf(1);
    Integer d = Integer.valueOf(1);
    

    See also

    • Weird Integer boxing in Java
    • How to properly compare two Integers in Java?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that the attributes of class which are declared by double underscore __
I know that in PHP, the only difference between double quotes and single quotes
We know that VB string start and end with double quotes So we have
I have two double a, b; I know that the following is true -1
So in the meanwhile we know that double-checked-locking as is does not work in
Does anyone know where I can find that algorithm? It takes a double and
I know that Java have its own garbage collection, but sometimes I want to
I know that immutable objects always have the same state, the state in which
I know that size of various data types can change depending on which system
I know that if we want to display a double as a two decimal

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.