I'm building e-commerce application and i have one case scenario where i need to cross out sizes which are not available in store.
I have fixed arraylist of strings with sample like this: "36", "38", "40", "42"
and i have available sizes with sample like this: "36", "38", "40"
Now i need to iterate through first array and cross out those sizes which are not available.
Here is one part of code where i'm doing that:
// tempSizes - available sizes
// mProduct.getSizes() - all sizes
for (String tempSize : tempSizes) {
for (int i = 0; i < mProduct.getSizes().size(); i++) {
if (tempSize.equals(mProduct.getSizes().get(i))) {
// if size is available
sizes.add(new Size(mProduct.getSizes().get(i), true));
} else {
// if size is not available
sizes.add(new Size(mProduct.getSizes().get(i), false));
}
}
}
Problem here is that nested for loop will be called three times and the result will output with duplicates of sample. If there is an easier way to do this, please let me know, i would appreciate it.
ArrayLists, though.36, 38, 40and available sizes are36, 38the output will be36(available), 38, 40, 36, 38(available), 40and it should be something like this:36(available), 38(available), 40