?public static void main(String[] args) {? ?int x[]={1,2,3,2,5,3,7,3,8,2,4,9,3,2,6,4};? ?Map map = new HashMap();? ?? ?for (int i : x) { ? Integer c = (Integer) map.get(i); ?if( c==null) ? { map.put(i,1);} //請解釋下這段代碼。 ?謝謝 ?else ? {map.put(i,c+1);}//請解釋下這段代碼。 ?謝謝 ? }? ?System.out.println(map);}? ?? ?? }
1 回答
已采納

甫艾蒽廷
TA貢獻38條經(jīng)驗 獲得超21個贊
map.put(鍵,值) 在map中存儲是以鍵值對的形式存儲數(shù)據(jù)的,鍵是唯一的。
這兩行你就明白了吧。就是以 i 為鍵, 1 或者 c+1 為值存儲。
滿意請采納!
添加回答
舉報
0/150
提交
取消