如何将 HashSet <String> 类型的集合中的所有字符串转换为小写?

How to convert all String's to lower case in a collection of type HashSet <String>?

我不确定将集合中的所有字符串转换为小写的最佳方法。有什么想法吗?

    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());