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]);
}
For the case of
BigIntegerandBigDecimalyou can just cast that (and all numeric primitive wrapper classes as well) toNumberand get thelongValue()(be careful when overflowing the range oflong‘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?