Given list of customers, I need to create another list with first names of customers in upper case. This is the code in java-
List<String> getFirstNames(List<Customer> customers)
{
List<String> firstNames = new ArrayList<>();
for(Customer customer: customers) {
firstNames.add(StringUtils.uppercase(customer.getFirstName());
}
return firstNames;
}
How do I write this method using lambda in java8. I could use streams in this way, to convert to list-
customers.stream().map(Customer::getFirstName).collect(Collectors.toList());
But, how can I convert firstName to upper case, using this?
customers.stream().map(Customer::getFirstName).map(StringUtils::uppercase).collect(toList());StringUtils.uppercase(customer.getFirstName())instead of simplycustomer.getFirstName().toUpperCase()?