Java List<String> to Short -
i have list of string:
private final list<string> categorylist = arrays.aslist("27", "28, 96", "10", "15", "7", "98");
from above list, "28, 96" considered 1 item (not typo). converting each of them short have no problems except 1 item:
for ( int m = 1; m < categorylist.size(); m++) { short layervalue = short.parseshort(categorylist.get(m)); }
i'm getting error converting "28, 96":
java.lang.numberformatexception: input string: "28, 96" @ java.lang.numberformatexception.forinputstring(numberformatexception.java:65) @ java.lang.integer.parseint(integer.java:492) @ java.lang.short.parseshort(short.java:117) @ java.lang.short.parseshort(short.java:143)
but if add directly:
//pmtpselectlist[0].layerratelist = new short[] {layervalue}; pmtpselectlist[0].layerratelist = new short[] {28, 96};
it works properly. so, i'm confused why , if there's way convert need loop couple of values replace layervalue (short)??? ty
you need split part aswell in second loop
for (string shortstr : categorylist) { string[] splitstr = shortstr.split(','); (string innershort: splitstr) { short layervalue = short.parseshort(innershort.trim()); // add list } }
Comments
Post a Comment