How do I iterate and modify Java Sets?

前端 未结 5 1510
既然无缘
既然无缘 2020-12-13 03:19

Let\'s say I have a Set of Integers, and I want to increment every Integer in the Set. How would I do this?

Am I allowed to add and remove elements from the set whi

5条回答
  •  不思量自难忘°
    2020-12-13 03:44

    I don't like very much iterator's semantic, please consider this as an option. It's also safer as you publish less of your internal state

    private Map JSONtoMAP(String jsonString) {
    
        JSONObject json = new JSONObject(jsonString);
        Map outMap = new HashMap();
    
        for (String curKey : (Set) json.keySet()) {
            outMap.put(curKey, json.getString(curKey));
        }
    
        return outMap;
    
    }
    

提交回复
热议问题