Java One pass without using replace function
Directly using the replace function for many times is not correct, unless you can do the replacements at the same time.\n\n\nclass Solution {\n    \n    public 
Directly using the replace function for many times is not correct, unless you can do the replacements at the same time.\n\n```\nclass Solution {\n    \n    public String entityParser(String text) {\n        if(text == null || text.length()==0) return "";\n        \n        Map<String, Character> map = new HashMap<>();\n        map.put("quot", \'\\"\');\n        map.put("apos", \'\\\'\');\n        map.put("amp", \'&\');\n        map.put("gt", \'>\');\n        map.put("lt", \'<\');\n        map.put("frasl", \'/\');\n        \n        StringBuilder res = new StringBuilder();\n        for(int i=0; i<text.length(); ++i) {\n            if(text.charAt(i) != \'&\') {\n                res.append(text.charAt(i));\n            } else {\n                int j = i+1;\n                while(j < text.length() && text.charAt(j)!=\';\') {\n                    ++j;\n                }\n                if(j == text.length()) {\n                    res.append(text.substring(i));\n                    break;\n                } else {\n                    String key = text.substring(i+1, j);\n                    if(map.containsKey(key)) {\n                        res.append(map.get(key));\n                    } else {\n                        res.append(\'&\').append(key).append(\';\');\n                    }\n                    i = j;\n                }\n            }\n        }\n            \n        return res.toString();\n    }\n}\n```
[]