用java如何得到List<String>中重复的字符比如["abc","bcf","cfg"]得到c
时间: 2023-09-28 17:10:12 浏览: 173
抱歉,我可以回答这个问题。你可以通过遍历List<String>中的每个字符串,再遍历每个字符串中的每个字符,使用HashMap<String, Integer>来统计每个字符出现的次数,最后再遍历HashMap,找出出现次数大于1的字符即可。以下是示例代码:
```
List<String> list = Arrays.asList("abc", "bcf", "cfg");
Map<String, Integer> map = new HashMap<>();
// 统计每个字符出现的次数
for (String str : list) {
for (char c : str.toCharArray()) {
String key = String.valueOf(c);
map.put(key, map.getOrDefault(key, 0) + 1);
}
}
// 找出出现次数大于1的字符
List<String> result = new ArrayList<>();
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() > 1) {
result.add(entry.getKey());
}
}
System.out.println(result); // 输出 [c]
```
相关问题
Traceback (most recent call last): File "/private/var/containers/Bundle/Application/A25BCF53-C714-46D1-9B4B-6C2B084A6D1F/Python.app/pythonLib/internal/CodeRunner.py", line 75, in run exec(str(code),gl) File "<string>", line 25, in <module> File "<string>", line 13, in tts File "/var/mobile/Containers/Data/Application/29BEF95C-12A2-4081-9E12-97573181A450/Documents/defaultMainPath/site-packages/gtts/tts.py", line 324, in save with open(str(savefile), "wb") as f: PermissionError: [Errno 1] Operation not permitted: 'voice.mp3'
这是一个 Python 的错误,它发生在尝试保存一个 mp3 文件时,因为没有权限而失败了。这可能是因为您没有写入文件的权限,或者文件正在被其他程序占用。您可以尝试更改文件的权限或关闭其他程序,然后再次尝试保存 mp3 文件。
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=/favicon.ico><link rel=stylesheet type=text/css id=style href=/mob.css><title>泰迪内推</title><link href=/static/css/chunk-213d46f9.6699f04d.css rel=prefetch><link href=/static/css/chunk-27f03f86.a14eed06.css rel=prefetch><link href=/static/css/chunk-3e1db89a.80dc307b.css rel=prefetch><link href=/static/css/chunk-43ac0f34.b39cf2e8.css rel=prefetch><link href=/static/css/chunk-47eb0788.1ef261ba.css rel=prefetch><link href=/static/css/chunk-4df08e90.c15bd54f.css rel=prefetch><link href=/static/css/chunk-604a0331.222a69ed.css rel=prefetch><link href=/static/css/chunk-706e4bb8.ba0c435d.css rel=prefetch><link href=/static/css/chunk-aa019e9e.a24ffcbe.css rel=prefetch><link href=/static/css/chunk-b2d8146e.9f5c8495.css rel=prefetch><link href=/static/js/chunk-0bd9655e.5d19cfbe.js rel=prefetch><link href=/static/js/chunk-213d46f9.5bf0f607.js rel=prefetch><link href=/static/js/chunk-27f03f86.5642dd75.js rel=prefetch><link href=/static/js/chunk-2d0b35ec.0914afe2.js rel=prefetch><link href=/static/js/chunk-2d0dd3b6.0661684c.js rel=prefetch><link href=/static/js/chunk-2d217c6c.0552e504.js rel=prefetch><link href=/static/js/chunk-3e1db89a.32ad918c.js rel=prefetch><link href=/static/js/chunk-43ac0f34.cae47384.js rel=prefetch><link href=/static/js/chunk-47eb0788.f22bea25.js rel=prefetch><link href=/static/js/chunk-4c5e9add.e9181098.js rel=prefetch><link href=/static/js/chunk-4df08e90.a647fb2c.js rel=prefetch><link href=/static/js/chunk-50ab568d.23c2b33f.js rel=prefetch><link href=/static/js/chunk-580d01b5.865ed0ae.js rel=prefetch><link href=/static/js/chunk-604a0331.ff94cd57.js rel=prefetch><link href=/static/js/chunk-706e4bb8.cc1fe1f6.js rel=prefetch><link href=/static/js/chunk-70d08bcf.6283edd1.js rel=prefetch><link href=/static/js/chunk-aa019e9e.a3ad5f18.js rel=prefetch><link href=/static/js/chunk-b2d8146e.cc40e92f.js rel=prefetch><link href=/static/js/chunk-c5bd1154.0a2126f9.js rel=prefetch><link href=/static/js/chunk-f5ae8c94.d4d5a49c.js rel=prefetch><link href=/static/css/chunk-vendors.a57aa87f.css rel=preload as=style><link href=/static/css/frontend.8e826938.css rel=preload as=style><link href=/static/js/chunk-vendors.ce9424b8.js rel=preload as=script><link href=/static/js/frontend.6f4ec638.js rel=preload as=script><link href=/static/css/chunk-vendors.a57aa87f.css rel=stylesheet><link href=/static/css/frontend.8e826938.css rel=stylesheet></head><body><div id=app></div><script src=/static/js/chunk-vendors.ce9424b8.js></script><script src=/static/js/frontend.6f4ec638.js></script></body></html>
这是一个HTML文档,包含了HTML标签、元数据和引用的CSS和JS文件等。具体来说,DOCTYPE表示文档类型声明,html表示文档的根节点,lang=en表示文档使用的语言为英文。head标签包含了文档的元数据,包括字符集、兼容性模式、视口设置、标题、图标等。body标签包含了文档的主体内容,其中id为app的div标签可能是网页的主体内容容器。文档中还引用了多个CSS和JS文件,可以通过这些文件来渲染和控制网页的样式和行为。
阅读全文