I have an object in my Customer application that has a list of customers.
public class CustomerList { private List<Customer> }
In the class of customers, in turn, there is a list of all the goods that they bought in the store on a specific day of the week.
public class Customer { private List<String> itemsOnMonday; private List<String> itemsOnTuesday; private List<String> itemsOnWednesday; private List<String> itemsOnThursday; private List<String> itemsOnFriday; }
Now I want to get a list of all the items that the customer bought in a week. What is the best way to do this? My colleague suggests creating another list and adding items to this list. I am not sure if this is a good approach. I have more than 1000 clients, and each client sells more than 500 items per week. He offers something like this -
for(Customer customer:customerList) { List<String> items = new ArrayList<String>(); items.addAll(itemsOnMonday);
This is crazy because I will create more than 1000 objects inside the for loop. Any thoughts on a better way to do this? For some time we stormed the brain and cannot come up with an effective implementation for this. Any help would be greatly appreciated.
source share