I am facing of memory exception while running this code and the constraint is heap size. Can anyone suggest if there is a way to optimize this code further?
public class getCustomerList {
public static List <Customer> retrieve() throws ParseException {
List<Customer> customers = new ArrayList<Customer>();
for (int i = 0; i < 100000; i++) {
Customer customer = new Customer();
customer.setAge(new Integer(i));
customer.setBirthDate((new SimpleDateFormat("ddMMyyyy")).parse("01061986"));
customer.setName("Customer" + new String((new Integer(i)).toString()));
customers.add(customer);
}
return customers;
}
}