Complete the code to declare a simple DTO class with a private field and a getter.
public class UserDTO { private String [1]; public String getName() { return name; } }
The field name matches the getter getName(), which is typical in DTOs.
Complete the code to create a constructor for the DTO that sets the name field.
public class UserDTO { private String name; public UserDTO([1]) { this.name = name; } }
The constructor parameter must match the field type and name to set the value correctly.
Fix the error in the DTO setter method to correctly set the field.
public void setName(String name) {
[1] = name;
}this.Using this.name refers to the field, avoiding confusion with the parameter name.
Fill both blanks to create a DTO from an entity object.
public UserDTO([1] user) { this.name = user.[2](); }
The constructor takes a User entity and calls its getName() method to set the DTO's name.
Fill all three blanks to convert a list of entities to a list of DTOs using streams.
List<UserDTO> dtos = users.stream()
.map(user -> new UserDTO(user.[1]()))
.[2](Collectors.[3]());The stream maps each user by calling getName(), then collects the results into a list using collect(Collectors.toList()).