What is integer boxing in java

0 votes
Mar 6, 2019 in Java by Phalguni
• 1,020 points
2,337 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, 2019 by Avantika
• 1,520 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,220 points
3,181 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,120 points
3,814 views
0 votes
2 answers

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,190 points
62,769 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, 2019 in Java by Sirajul
• 59,230 points
3,128 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,620 points
1,332 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,620 points
822 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,190 points
791 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,120 points
2,856 views
+1 vote
4 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, 2019 in Java by Sirajul
• 59,230 points
65,040 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, 2019 in Java by Avantika
• 1,520 points

edited Feb 28, 2019 by Omkar 17,949 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP