can anyone explain me the concept of autoboxing?

Answers were Sorted based on User's Feedback



can anyone explain me the concept of autoboxing?..

Answer / durga ganesh reddy

autoboxing is that the conversion of primitive data types
into wrapper class objects automatically.By using generic
types of java 1.5,we an acheive it easily.By declaring, the
collection classes as shown below we can do it.
HashSet<Integer> hs=new HashSet<Integer>();
hs.add(1);
hs.add(2);
Iterator it=hs.iterator(0;
while(it.hasNext())
System.out.println(it.next());

Is This Answer Correct ?    11 Yes 0 No

can anyone explain me the concept of autoboxing?..

Answer / jitu

In case of autoboxing directly the value of the constructor
assign to a variable.i.e object of wrapper class directly
assign to a variable.but it is only possible in case of 1.5
version.
Ex:public class X
{public static void main(String a[])
{Integer i1=new Integer("20");
Integer i2=new Integer("20");
int m1=i1;
int m2=i2;
S.o.p(m1+m2);o/p-20

Is This Answer Correct ?    3 Yes 0 No

can anyone explain me the concept of autoboxing?..

Answer / srinu

auto boxing:-
The process of conversion of primitive data type into wraper
class object into AUTOMATICALLY is called Auto boxing.
By using generic types of java 1.5,we an acheive it
easily.By declaring, the collection classes as shown below
we can do it.
EX:

HashSet<Integer> hs=new HashSet<Integer>();
hs.add(1);
hs.add(2);
Iterator it=hs.iterator();
while(it.hasNext())
{

System.out.println(it.next());
}
(Note: original it.next() returns object but here
System.out.println print primitive datatypes.

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More Core Java Interview Questions

Can we access the non-final local variable, inside the local inner class?

0 Answers  


How many bytes are a float?

0 Answers  


How many objects are created for a singleton class

7 Answers   Ness Technologies,


When will you define a method as static?

0 Answers  


What is break and continue statement?

0 Answers  






What do you mean by boolean?

0 Answers  


What is double data type?

0 Answers  


What are the names of interfaces that doesn't consists of method/s ?

3 Answers  


What means public static?

0 Answers  


84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query(”GET INFO FROM CUSTOMER”); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? 1 Line 92 will not execute. 2 The connection will not be retrieved in line 85. 3 The resource connection will not be closed on line 88. 4 The enclosing method will throw an exception to its caller.

1 Answers  


Program to find greatest prime number in n numbers?

3 Answers   Huawei,


How many types of memory areas are allocated by jvm?

0 Answers  


Categories