java replace arraylist of strings -
java replace arraylist of strings -
i can't seem figure out how replace array list of strings.
arraylist<string[]> records
so within loop want replace record can maintain getting error.
the method set(int, string[]) in type arraylist not applicable arguments (int, string)
(int = 0; < records.size(); i++) { (int j = 0; j < 2; j++) { if (j == 0) { if(!validaterecords(records.get(i)[j].tostring())) { logging.info("records not parsed " + records.get(i)[j].tostring()); records.set(j, "couldnotbeparsed"); }else { logging.info(records.get(i)[j].tostring()+ " has been sanitized"); } } } }
what proper way replace record using records.set() ?
since not replacing entire array, changing single entry in existing array, need utilize get()
followed array write, instead of set()
:
if(!validaterecords(records.get(i)[j].tostring())) { logging.info("records not parsed " + records.get(i)[j]); records.get(i)[j] = "couldnotbeparsed"; } else { logging.info(records.get(i)[j] + " has been sanitized"); }
note if (j == 0)
check within loop looks highly suspicious, because in effect makes loop on j
exclusively useless. might write this:
for (int = 0; < records.size(); i++) { if(!validaterecords(records.get(i)[0].tostring())) { logging.info("records not parsed " + records.get(i)[0]); records.get(i)[0] = "couldnotbeparsed"; } else { logging.info(records.get(i)[0] + " has been sanitized"); } }
also note calls of tostring()
not necessary when concatenate strings: java compiler insert them you, , take care of null
values you.
java arraylist replace
Comments
Post a Comment