String [] a ={a,b,c,a,c,b,d,e};
String [] b ={1,2,3,1,3,2,4,5};
数组的长度是一样的
怎么把数组的值分类
把a,1是一组 b,2是一组 c,3是一组 d,4是一组。无限
怎么把相同的全部成一个组,有多少个相同的值
比如:
a,1有多少个相同的,b,2有多少个相同的,c,3有多少个相同的
这应该怎么做
String [] b ={1,2,3,1,3,2,4,5};
数组的长度是一样的
怎么把数组的值分类
把a,1是一组 b,2是一组 c,3是一组 d,4是一组。无限
怎么把相同的全部成一个组,有多少个相同的值
比如:
a,1有多少个相同的,b,2有多少个相同的,c,3有多少个相同的
这应该怎么做
解决方案 »
- Could not execute JDBC batch update(hibernate+spring)
- java 修改 properties文件
- 怎样在myeclipse中建立mysql数据库
- 如何把 .war 文件导入 myeclipse 里?
- j2ee的学习
- 如何在action中知道jsp中选择了哪个下拉菜单?
- ExtJs 3.0中文API 下载
- struts使用超链接跳转出现白屏(小弟跪求高人指点)
- 怎样在java文件中调用另一个模块的ejb?
- ConstraintViolationException异常,但没有执行 catch(ConstraintViolationException e)中的代码
- 如何得打活动目录用户名对应的密码?
- EJB
String [] a ={a,b,c,a,c,b,d,e};
String [] b ={1,2,3,1,3,2,4,5};
Map<String, Integer> group = new HashMap<String, Integer>();
StringBuilder buf = new StringBuilder();
for (int i=0; i<a.length; i++) {
buf.delete(0, key.length());
buf.append(a[i]).append(",").append(b[i]);
String key = buf.toString();
if (group.containsKey(key)) {
group.put(key, grout.get(key)+1);
} else {
group.put(key, 1);
}
}
System.out.printf("has %d group\n", map.size());
for (Map.Entry<String, Integer> e : map.entrySet()) {
System.out.printf("group[%s], count[%d]\n", e.getKey(), e.getValue());
}
把相同的值归成一类然后输出 这有什么好的方法做?
for(String str:set){
System.out.printlf("%s:%d",str,group.get(str));
}
group[c,3], count[2]
group[e,5], count[1]
group[a,1], count[2]
group[b,2], count[2]输出来是这个样子
但我要输出的是
group[d,4]
group[c,3]
group[e,5]
group[a,1]
group[b,2]
这里面的两个值输出
比如:
d,4 count[1]
c,3 count[2]
怎么做?
那你就自己取d,4和c,3打印就好了
比如
System.out.printf("d,4 count[%d]\n", map.get("d,4"));
System.out.printf("c,3 count[%d]\n", map.get("c,3"));想打印什么自己从map里取出来打印就可以了
我现在要把d,4单独打印出来