For each loop on Java HashMap

后端 未结 4 1865
抹茶落季
抹茶落季 2021-02-05 08:21

A basic chat program I wrote has several key words that generate special actions, images, messages, etc. I store all of the key words and special functions in a HashMap. Key wor

4条回答
  •  后悔当初
    2021-02-05 09:17

    If you need access to both key and value then this is the most efficient way

        for(Entry e : m.entrySet()) {
            String key = e.getKey();
            String value = e.getValue();
        }
    

提交回复
热议问题