top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to convert an int into Integer in java and what is difference between two?

+1 vote
How to convert an int into Integer in java and what is difference between two?
posted Jun 27, 2017 by Ajay Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
Best answer

Something like this -

public class IntToIntegerExample {
  public static void main(String[] args) {
    int i = 10;   
    Integer intObj = new Integer(i);  // Integer constructor to convert int primitive type to Integer object.

int vs Integer
The main difference between two is that the 'int' type is a primitive , whereas the 'Integer' type is an object.

Object vs Primitive
Objects provide facilities for polymorphism, are passed by reference and are allocated from the heap. Whereas primitives are immutable types that are passed by value and are often allocated from the stack.

answer Jun 27, 2017 by Salil Agrawal
Similar Questions
+2 votes

I want to convert a string say "98989" into an integer without using any library functions in java. Give fastest way to do it and explain why your method is best.

0 votes

I am search for different approach.
Let see how many solution i can get

0 votes

Given an unordered array A of size n and integer x. What is the best complexity to find two elements in A whose sum is x?
Share the algo, its complexity and if possible C code.

+1 vote

int arr[ ] = { 1, 2 };
p = arr; /* p is pointing to arr */

How pointer p will behave ?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.