Java Integer Wrapper Class Related -


public class testme{  public static void main(string[] args)  {    integer = 128;    integer j = 128;     integer k = 12;    integer l = 12;     system.out.println(i == j);      system.out.println(k == l);   } } 

i'm getting output: false true

why 1st 1 false , 2nd 1 true?

see: http://javapapers.com/java/java-integer-cache/

short answer:

in java 5, new feature introduced save memory , improve performance integer type objects handlings. integer objects cached internally , reused via same referenced objects.

this applicable integer values in range between –127 +127.

this integer caching works on autoboxing. integer objects not cached when built using constructor.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -