I am trying to iterate a list which contains multiple Ids like this:
[148066, 148065, 148064, 148063, 148062, 148061, 148060, 148059, 148058, 148057, 148056]
List<String> list= DbService.getPayUVerificationList();
where this above list object contains all the fetched Ids from DB.
if(null != list && !list.isEmpty())
{
for (int i = 0; i < list.size(); i++) {
//System.out.println(list.get(i));
//String txnId= list.get(i).toString();
//String txnId = (String) list.get(i);
//String txnId = (String) list.get(i);
String txnId = (String) list.get(i).toString();
String output=hdfcService.checkPayStatusByPayU(txnId);
}
}
but i am getting
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
I have tried lot of casting and approaches but all in vain.
Edit 1: As many are saying that this "list.get(i).toString()" should work but in my case this is still not working and i have no idea about this.
String txnId = String.valueOf(list.get(i))?list.get(i).toString()itself, which the OP has already tried. Ideally it should work