Java 如何转换所有字符串';在HashSet类型的集合中,将s改为小写<;字符串>;?

Java 如何转换所有字符串';在HashSet类型的集合中,将s改为小写<;字符串>;?,java,string,collections,hashset,lowercase,Java,String,Collections,Hashset,Lowercase,我不确定将集合中的所有字符串转换为小写的最佳方法。有什么想法吗 private Set<String> email; if(userEmail instanceof Collection) { this.email = new HashSet<String>((Collection<String>) userEmail); model.put("userEmail", this.email); //need to co

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

    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
}
私人设置电子邮件;
if(收集的用户电子邮件实例){
this.email=新HashSet((Collection)userEmail);
model.put(“userEmail”,this.email);//需要将其转换为小写
}

提前感谢:-)

要将
集中的值转换为小写,请不要使用该构造函数,只需在将字符串添加到集合之前将其转换为小写:

this.email = ((Collection<String>) userEmail).stream()
        .map(String::toLowerCase).collect(Collectors.toSet());
this.email=((集合)userEmail).stream()
.map(字符串::toLowerCase).collect(收集器.toSet());

this.email=new HashSet();
对于(字符串s:(集合)用户电子邮件)
this.email.add(s.toLowerCase());
这是您的答案。可能是:你为什么要这么做?如果是因为需要查找字符串而不区分大小写,请使用
新树集(String.case\u INSENSITIVE\u ORDER)
而不是
哈希集
,这样在构建集和查找值时就不必转换为小写。
this.email = new HashSet<>();
for (String s : (Collection<String>) userEmail)
    this.email.add(s.toLowerCase());