answersLogoWhite

0


Best Answer

Java has auto-boxing introduced in Java 5 and converts ints to Integer objects as needed.

Or you can explictly call Integer.valueOf(int) or new Integer(int) to return an Integer object with the value of the primitive int argument.

Example:

int i = 14; // i = 14
Integer a = Integer.valueOf(i); // a = 14Integer b = new Integer(i); // b = 14
or simply
Integer c = i;

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you convert an int to object in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you convert string to int in Java?

One can convert a string variable to an int variable in Java using the parse integer command. The syntax is int foo = Integer.parseInt("1234"). This line will convert the string in the parenthesis into an integer.


How can someone convert string to int in Java?

To convert string to int in Java, the easiest way is to simply use the method Integer.parseInt(). For more information how to do this, refer to the integer class documents.


Why java is not a pure object oriented?

java is not purely oops because of primitive types in java like int and float double


How do you convert long value into int in java?

long a; int b; b = a.intValue(); //IMPORTANT NOTE IF THE LONG IS SO LARGE THAT IT CANT BE A INT THEN YOU WILL GET A OVERFLOW ERROR


How do you convert a char to an int in java?

Assuming - char mychar ; and int myint have been properly declared, myint = (int) mychar; // converts This is a feature of Java= to change types, put the type you want to convert into in parenthes before the variable that stores the converted value. ^Will convert your char into an int, but it will be the ascii value. For example, mychar = 3; myint = (int) mychar; //returns 51 To make an accurate one that will not return an error, you can use a try-catch statement Example char mychar = '3'; try { int myint = (int) mychar; }catch(NumberFormatException e) { //Do whatever you want with it! }


Can you write the code to compare 2 string objects in Java?

In java, the String object has a compareTo() method. The method returns an int. If the int is less than zero, the first string is less than the second. If the int is greater, the first is greater than the second. If the int is zero, the two strings are equal.


How do you initialize variable?

initialize simple types: int i = 0; initialize objects: Object o = null; (in java)


Why java is not a complete object oriented language?

Java is not a completely object oriented language, because not all values in Java are Objects. For example, the basic numeric types such as int, long, double, etc., are not objects and need to be "boxed" into objects in order to pass them as Object parameters or call methods on them.


What is the purpose of integer Java?

Within Java, an integer is an Object, which is converse to the "int", which is a primitive. In reality, this means that for an integer, a method can be called upon it, whereas with a primitive, this is not the case.


What is a int in java?

int is integer which means datatype


Why java not use int as a generic argument?

Only Objects can be used as generic arguments. Primitives Data Types (int, long, char ...) are not objects. But you can use Integer, an Object that wrap the data type int instead.


How you convert int to string in jsp?

The same way you would in a regular java program. int i = 10; String s = i + ""; after the above line of code the variable s will have "10" as a string value...