https://www.cnblogs.com/sunda847882651/p/9568199.html
public static void main(String[] args) throws IOException {
findRepeatChar("abcafeba");
}
//找串中第一个重复出现的字符
public static void findRepeatChar(String str){
HashSet hs=new HashSet();
char[] chs=str.toCharArray();
for(char c:chs){
boolean flag=hs.add(c);
if(!flag) {
System.out.println(c);
return;
}
}
}
```
本文介绍了一种使用HashSet在Java中找出字符串中第一个重复字符的方法。通过将字符串转换为字符数组并遍历,利用HashSet的特性判断字符是否已存在,从而高效地找到重复字符。
1771

被折叠的 条评论
为什么被折叠?



