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

  • Home
  • SEARCH
  • 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 683087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:40:06+00:00 2026-05-14T01:40:06+00:00

Integer i = 127; Integer j = 127; System.out.println(i == j); System.out.println(i.equals(j)); Integer i1

  • 0
Integer i = 127;
Integer j = 127;
System.out.println(i == j);
System.out.println(i.equals(j));

Integer i1 = 128;
Integer j1 = 128;
System.out.println(i1 == j1);
System.out.println(i1.equals(j1));

I don’t understand why its not print “true, true, true, true”. please give answer?

  • 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-05-14T01:40:07+00:00Added an answer on May 14, 2026 at 1:40 am

    When you use ==, you’re comparing the object instances for equality.

    The reason that the first two instances are equal is that you created the Integers by using autoboxing (rather than calling new Integer(127)), and the Java Language Specification §5.1.7 requires that Integers between -128 and 127 are cached.

    Implementations can cache more values than that but are not required to; apparently the JVM you are using does not cache 128. This is the case for Sun Java 6.

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

Sidebar

Related Questions

Integer integer1 = 127; Integer integer2 = 127; System.out.println(integer1 == integer2);//true integer1 = 128;
I want to convert a floating point user input into its integer equivalent. I
I'm trying to output some data to file in Java and do not understand
§5.2.4.2.1 of C99 defines SCHAR_MIN as -127 and SCHAR_MAX as 127. Should not the
I am attempting to devise a system for packing integer values greater than 65535
Possible Duplicate: Integer wrapper objects share the same instances only within the value 127?
Given this code which prints all the bits in an integer out: private string
An integer's max value in Java is 2147483647, since Java integers are signed, right?
Dynamic integer will be any number from 0 to 150. i.e. - number returns
Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I

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.