Java - lambda - 將串列 A 轉成 串列 B
List<ProductManager> B = A.stream()
.map(developer -> new ProductManager(developer.getName(), developer.getAge()))
.collect(Collectors.toList());
List<ProductManager> B = A.stream().map(developer -> {
ProductManager productManager = new ProductManager();
try {
PropertyUtils.copyProperties(productManager, developer);
} catch (Exception ex) {
ex.printStackTrace();
}
return productManager;
}).collect(Collectors.toList());
B.forEach(System.out::println);