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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:05:50+00:00 2026-06-14T10:05:50+00:00

Codes : Integer a1 = 100; Integer a2 = 100; System.out.println(a1 == a2); //

  • 0

Codes :

Integer a1 = 100;
Integer a2 = 100;
System.out.println(a1 == a2);   // true

Integer b1 = new Integer(100);
Integer b2 = new Integer(100);
System.out.println(b1 == b2);   // false

Integer c1 = 150;
Integer c2 = 150;
System.out.println(c1 == c2);   // false  

Java designs that when using AutoBoxing, values between -128 and 127 appear to refer to the same Integer objects, which causes different results of the first code fragments and the last one

My question is : Why does java design it like this, are there any advantages ?

  • 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-14T10:05:51+00:00Added an answer on June 14, 2026 at 10:05 am

    The simple rationale is that it’s useful/efficient to have a set of Integers already created and available for boxing. It’s very likely that if an application will need boxed integers, they’re going to be in a certain range (e.g. 1… whatever). The fact that they’re boxed up to -127/128 is a simple design heuristic based upon what’s likely to provide benefit without pre-boxing a huge number of integers.

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

Sidebar

Related Questions

Consider the following two segments of code in Java, Integer x=new Integer(100); Integer y=x;
I currently have code in objective C that can pull out an integer's most
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
Here is my code: new Loading.LoadTast(ctx) { @Override protected String doInBackground(Integer... params) { Looper.prepare();
I try use a integer array in java with the code below: public static
I have a website with a Java Applet and that applet needs to connect
I've designed a class that fills an array with integers using a various number
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
I'm new to using OOP, I typically just put all my code in a
simonn helped me to code an ordered integer partition function here. He posted two

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.