I need to convert array of Objects into a Long/Integer.. Problem is that those Objects are sometimes BigIntegers, sometimes BigDecimals and sometimes even something else. Is there any good libraries for accomplishing this?
for example...
for (Object[] o : result) {
Long l = SomeClass.convertToLong(o[0]);
Integer i = SomeClass.convertToInt(o[1]);
}
You can get pretty far with Number:
Long l = ((Number) object).longValue();
Integer i = ((Number) object).intValue();
For the case of BigInteger
and BigDecimal
you can just cast that (and all numeric primitive wrapper classes as well) to Number
and get the longValue()
(be careful when overflowing the range of long
'though).
If they are something else, then you'd need some rules on how to convert it anyway. What "something else" do you have in mind?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With