public static void main(String[] args) {
String[] a = {"java","c++","c++","java","c#","bootstrap","java"};
Set<String> nonDuplicateSet = new HashSet<String>();
Set<String> duplicateSet = new HashSet<String>();
for(String abc:a){
if(!nonDuplicateSet.contains(abc)){
nonDuplicateSet.add(abc);
}else{
duplicateSet.add(abc);
}
}
System.out.println(duplicateSet);
如何计算java重复3次/ c ++重复2次
答案 0 :(得分:0)
这会对你有所帮助
`String[] a = {"java","c++","c++","java","c#","bootstrap","java"};
Map<String, Integer> map = new HashMap<String, Integer>();
for(String str :a){
if(map.containsKey(str)){
map.put(str, map.get(str)+1);
}else{
map.put(str, 1);
}
}`
和for entrySet计算。