What is integer boxing in java?

0 votes
Mar 6 in Java by Phalguni
• 1,010 points
22 views

1 answer to this question.

0 votes

In Java the boxing range for any integer is between -128 and 127. So whenever you use numbers in this specified range, you can compare it with the “==” operator. But for Integer objects outside the range you can only use equals.

Autoboxing in Java is converting a primitive value into an object of the corresponding wrapper class eg. Converting int to integer class.

Unboxing in Java refers to converting an object of a wrapper type to its corresponding primitive value eg. Conversion of Integer to int.

Here is an illustration of autoboxing and unboxing:

1.        import java.io.*;
2.        import java.util.*;
3.        class Integer_Boxing
4.        {
5.        public static void main (String[] args)
6.        {
7.        List<Integer> list = new ArrayList<Integer>();
      for (int i = 0; i < 10; i++)
9.        list.add(i);
10.     }
11.     }

In the above example we are including int primitive types rather than Integer Object.

Hope this helps!!

answered Mar 6 by Avantika
• 1,500 points

Related Questions In Java

+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
196 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,040 points
301 views
0 votes
1 answer

What is the difference between Set and List in java?

List is an ordered sequence of elements. ...READ MORE

answered Apr 26, 2018 in Java by Akrati
• 3,150 points
60 views
0 votes
1 answer

What is the use of @Override annotation in Java ? When do we use it ?

I think it is most useful as ...READ MORE

answered May 4, 2018 in Java by Akrati
• 3,150 points
68 views
0 votes
1 answer

What is the concept of Immutability for strings in Java ? Why are strings immutable ?

According to Effective Java, chapter 4, page 73, ...READ MORE

answered May 11, 2018 in Java by Rishabh
• 3,540 points
125 views
0 votes
1 answer

What is the 'instanceof' operator used for in Java?

It's an operator that returns true if ...READ MORE

answered May 23, 2018 in Java by Rishabh
• 3,540 points
50 views
0 votes
1 answer

What is the difference == and equals() in Java?

Both the answers (Syntaxes) are correct. If ...READ MORE

answered Jun 5, 2018 in Java by Akrati
• 3,150 points
26 views
0 votes
1 answer

What is Classpath in java?

Classpath is a parameter in the Java virtual machine or ...READ MORE

answered Jun 5, 2018 in Java by Daisy
• 8,040 points
252 views
0 votes
1 answer

What is the difference between string object and string literal?

Difference between string objects and string literals A ...READ MORE

answered Feb 28 in Java by Avantika
• 1,500 points

edited Mar 15 by Kalgi 50 views
0 votes
1 answer

How does Java convert integer value into byte?

When an integer value is converted into ...READ MORE

answered Feb 28 in Java by Avantika
• 1,500 points

edited Feb 28 by Omkar 106 views