在java的Map集合中,怎样更改value的值

时间:2025-02-09 09:00:23
import  ;
import  ;
 
public  class  Demo {
     public  static  void  main(String[] args) {
         Map<Integer,Integer> m =  new  HashMap<Integer,Integer>();
         ( 1 1 );
         print(m);
         ( 1 2 );
         print(m);
     }
 
     private  static  void  print(Map<Integer, Integer> m) {
         for (<Integer, Integer> mm : ())
             ( "K: " +()+ ",V: " +());
     }
}
 
//供参考,重新放一个相同的key,会自动覆盖value的。

相关文章