public static void main(String[] args) {
String str[][] = {{"a","b","c"},{"d","e"},{"f"}};
int num = str.length;
System.out.println("======数组外部长度>>>>" + num);
for (int i = 0; i < str.length; i++) {
int num2 = str[i].length;
System.out.println("======数组内部长度>>>>" + num2);
}
}
追问我的意思是求出每个元素有重复的个数:例如{1,1,2,3,4,5} 求出1 有几个,2有几个,3有几个,4有几个,5有几个
追答import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class TestDuplicateCount {
public static void main(String args[]){
int [] array = {1,1,2,3,4,5,5,5,9,0,9,10};
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
for(int i = 0; i < array.length;i++){
if(!map.isEmpty() && map.containsKey(array[i])){
map.put(array[i], map.get(array[i]) + 1);
}
else{
map.put(array[i], 1);
}
}
Set<Integer> set = map.keySet();
for (Integer key : set) {
System.out.println(key + "==>" + map.get(key));
}
}
}
result:
0==>1
1==>2
2==>1
3==>1
4==>1
5==>3
9==>2
10==>1