
Anonymous
Not applicable
2009-09-12
05:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Convert Long to Int
Hello all,
I need to convert from a long type to a int. I have used intValue() method but I get an error. I have tried to convert long to string with toString() but I get another error. Examples:
((new Date()).getTime()).intValue() --> Error
toString((new Date()).getTime()) --> Error
Can anyone help me?
Regards, Nardinar
I need to convert from a long type to a int. I have used intValue() method but I get an error. I have tried to convert long to string with toString() but I get another error. Examples:
((new Date()).getTime()).intValue() --> Error
toString((new Date()).getTime()) --> Error
Can anyone help me?
Regards, Nardinar
943 Views
6 Replies

Anonymous
Not applicable
2009-09-14
12:12 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello guy
long l1=12l;
int i1=(int)l1;
Best regards
shong
long l1=12l;
int i1=(int)l1;
Best regards
shong
943 Views

Anonymous
Not applicable
2009-09-15
06:43 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I followed the solution given by Shong, as seen in the attached screenshot, yet I still get the error
Has anybody a solution to this?
I followed the solution given by Shong, as seen in the attached screenshot, yet I still get the error
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot cast from Long to int
Has anybody a solution to this?
943 Views

Anonymous
Not applicable
2009-09-15
06:49 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
Uncheck the 'nullable' option of column.
Best regards
shong
Uncheck the 'nullable' option of column.
Best regards
shong
943 Views

Anonymous
Not applicable
2009-09-15
06:56 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Shong!
Unchecking the "Nullable" option was the solution.
In the meanwhile, I found another one, that worked with the "Nullable" option checked:
This does not work when "Nullable" is not checked.
I'd like to know the explanation of this and I'd like to know this kind of details, so that I do not need to ask simple questions on the forum.
Where can I get such information?
Thank you.
Unchecking the "Nullable" option was the solution.
In the meanwhile, I found another one, that worked with the "Nullable" option checked:
// to Integer ii from Long nn
ii = nn.intValue();
This does not work when "Nullable" is not checked.
I'd like to know the explanation of this and I'd like to know this kind of details, so that I do not need to ask simple questions on the forum.
Where can I get such information?
Thank you.
943 Views

Anonymous
Not applicable
2009-09-15
07:04 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
It is basic java knowledge, Long is a class which extends Object class,
intValue() is one of method of Long,
/**
* Returns the value of this <code>Long</code> as an
* <code>int</code>.
*/
public int intValue() {
return (int)value;
}
long is a data type.
Best regards
shong
It is basic java knowledge, Long is a class which extends Object class,
intValue() is one of method of Long,
/**
* Returns the value of this <code>Long</code> as an
* <code>int</code>.
*/
public int intValue() {
return (int)value;
}
long is a data type.
Best regards
shong
943 Views

Anonymous
Not applicable
2009-09-15
07:28 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To handle null values, java ternary operator can be used while converting type in a tMap.
Example : String to BigDecimal
Thanks and Regards,
Pravu Mishra.
Example : String to BigDecimal
row1.SALARY != null ? new BigDecimal(row1.SALARY) : null
Thanks and Regards,
Pravu Mishra.
943 Views
