我不确定将集合中的所有字符串转换为小写的最佳方法。有什么想法吗?
private Set<String> email;
if(userEmail instanceof Collection) {
this.email = new HashSet<String>((Collection<String>) userEmail);
model.put("userEmail", this.email); //need to convert this to lower case
}
提前感谢:-)
要将Set
中的值转换为小写,请不要使用该构造函数,只需将字符串转换为小写,然后再将其添加到集合中:
this.email = ((Collection<String>) userEmail).stream()
.map(String::toLowerCase).collect(Collectors.toSet());
或
this.email = new HashSet<>();
for (String s : (Collection<String>) userEmail)
this.email.add(s.toLowerCase());