搞了半天终于搞定了
途中也出了许多的空指针异常,都是马虎导致的。- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- public class test{
- public static void main(String []args){
- String []s={"19900801","19890801","19721230","19901010","19901010","19791010","19890801"};
- HashMap<String,Object> hm=new HashMap<String,Object>();
- int counter=1;
- for(int i=0;i<s.length;i++){
- if(hm.put(s[i].substring(4), hm.get(s[i].substring(4)))!=null){
- // System.out.println(s[i].substring(4)+"--------------->"+hm.get(s[i].substring(4)));
- int temp=(Integer) hm.get(s[i].substring(4));
- hm.remove(s[i].substring(4));
- hm.put(s[i].substring(4), temp+1);
- }
- else
- hm.put(s[i].substring(4), counter);
- }
-
- Set entries=hm.entrySet();
- Iterator iter = entries.iterator();
- while(iter.hasNext()){
- Map.Entry entry = (Map.Entry)iter.next();
- Object key = entry.getKey();
- Object value = entry.getValue();
- System.out.println(key+"--------------->"+value);
- }
- }
- }
-
复制代码 希望能有帮助 |
|