Complete the code to ensure the 'name' field cannot be null.
public class User { @[1] private String name; }
The @NotNull annotation ensures the field is not null but allows empty strings.
Complete the code to ensure the 'username' field is not null and not empty (no blank spaces).
public class Account { @[1] private String username; }
The @NotBlank annotation ensures the string is not null, not empty, and not just whitespace.
Fix the error in the code to ensure the 'tags' list is not null and contains at least one element.
public class BlogPost { @[1] private List<String> tags; }
The @NotEmpty annotation ensures the collection is not null and has at least one element.
Fill both blanks to validate 'email' so it is not null and not blank.
public class Contact { @[1] @[2] private String email; }
Using both @NotNull and @NotBlank ensures the email is not null and not blank. However, @NotBlank alone is enough for strings, but sometimes both are used for clarity.
Fill all three blanks to create a map of word lengths for words longer than 3 characters.
Map<String, Integer> wordLengths = words.stream()
.filter(word -> word.length() [1] 3)
.collect(Collectors.toMap(
word -> word.[2](),
word -> word.[3]()
));The filter uses > to select words longer than 3. The key is the uppercase word using toUpperCase(), and the value is the word length using length().