如何统计一个数组中重复数据的个数

2025-01-01 01:11:39
推荐回答(1个)
回答1:

import java.text.BreakIterator;
import java.util.HashMap;
import java.util.Map;

public class test {
public static void main(String args[]){
String[] ss={"大","小","前","大","小"};
Map map=new HashMap();
String sop="";
for (int i = 0; i < ss.length; i++) {
String temp=ss[i];
int count=0;
for (int j = 0; j < ss.length; j++) {
String temp2=ss[j];
if(temp==temp2){
count++;
}
map.put(ss[i], count);
}
}
System.out.println(map.toString());
}