Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Long type to Integer

Status
Not open for further replies.

luckydexte

Programmer
Apr 26, 2001
84
US
Hello all,

Does anyone know how to convert type of Long to an Integer?

Long count = function(); // Returns a long
Integer factor = (Integer) count;

This obviously does not work but I am not sure how to get around this. Hibernate only returns a type of Long when using an aggregate count function but I have to an Integer.

Any ideas?

Thanks in advance.

Brandon
 
int intValue()
Returns the value of this Long as an int.

_________________
Bob Rashkin
 
But if you want an Integer object you would just do this:
Code:
Integer factor = new Integer(function().intValue());
That way you get the value from the Long and use that to create a new Integer.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[[]Starbase47.com]
 
If you are using Java 5.0 or 6.0 then this will also work:

Integer factor = function().intValue();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top