Results 1 to 6 of 6

Thread: Convert int to Integer type

  1. #1
    Join Date
    Mar 2010
    Posts
    202

    Convert int to Integer type

    Hello,
    How can we convert a variable int to Integer? I am new to java and I think this is quit confusing in the beginning. So, if you guys have any idea about it then please help me with this. Any explanation with an sample code will be appreciated. Thank you in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Convert int to Integer type

    Hello,
    Until Java 1.4, I think this is what you are talking about.
    Check it out
    Code:
    inexp = new Integer(intexp);
    Since Java 5, it is automatic. That is if you do not even mention it explicitly it will be fine in java 5 and above, that is the code will run without any errors. If you need more information on the same then you can visit the sun's official site and there you can find more detailed information on the same.

  3. #3
    Join Date
    Nov 2009
    Posts
    359

    Re: Convert int to Integer type

    Hello,
    Integer objects are not mutable. If you have to do operations must go through int. If at the end, you need an object of type Integer, we must rebuild a Integer from the int that contains the result. I guess what I am trying to explain here. If you need more help regrading the same they you can post your query and we will try to explain you with your query.

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Convert int to Integer type

    Hello,
    Here is the code which will run for java 5 and above.
    Code:
    Integer ex = Integer.function valueOf() {
        [native code]
    }(1);
    ex = Integer.function valueOf() {
        [native code]
    }(ex.intValue()+1);

  5. #5
    Join Date
    Nov 2009
    Posts
    333

    Re: Convert int to Integer type

    Hello,
    In java5, it will work. Otherwise, it must be
    Code:
    Integer ex = Integer.valueOf (1);
    I have also been using this after the release of the java 5.
    And even this works
    Code:
    public static Integer valueOf (int ex)
    ...
    Since:
    1.5
    Hope you understand the concept and you will interpret accordingly.

  6. #6
    Join Date
    Nov 2009
    Posts
    330

    Re: Convert int to Integer type

    Hello,
    See, if the following example helps you
    Code:
    public class intexamp {
    
    public static void main(String[] args) {
    
    int ex = 10;
    
    
    Integer ob = new Integer(ex);
    
    System.out.println(ob);
    }
    
    }

Similar Threads

  1. Convert reference types in value type and vice versa
    By Terawa in forum Software Development
    Replies: 3
    Last Post: 13-02-2011, 07:41 AM
  2. How to convert character data to integer data
    By FFCookie in forum Software Development
    Replies: 8
    Last Post: 26-09-2010, 03:28 AM
  3. Replies: 4
    Last Post: 25-09-2009, 05:09 PM
  4. Convert Integer to a String in Binary Notation
    By Naval in forum Software Development
    Replies: 2
    Last Post: 16-03-2009, 09:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,252,251.51211 seconds with 16 queries