What is integer boxing in java?

0 votes
Mar 6 in Java by Phalguni
• 1,010 points
43 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
575 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,050 points
806 views
0 votes
2 answers

What is the difference between Set and List in java?

LIST SET Duplicates YES NO Order Ordered Depends on Implementation Positional Access YES NO List is an ordered sequence ...READ MORE

answered Aug 14 in Java by Sirajul
• 37,400 points
141 views
0 votes
2 answers

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

@Override annotation is used when we override ...READ MORE

answered Aug 14 in Java by Sirajul
• 37,400 points
111 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
182 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
67 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
43 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,050 points
330 views
0 votes
2 answers

What is the difference between string object and string literal?

A String literal is a Java language concept. This ...READ MORE

answered Aug 16 in Java by Sirajul
• 37,400 points
381 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 1,215 views