Interview friendly code | O(n) | Java Solution without using replace
\nclass Solution {\n    public String entityParser(String text) {\n        StringBuilder res = new StringBuilder();\n        Map<String, Character> hmap = new H
```\nclass Solution {\n    public String entityParser(String text) {\n        StringBuilder res = new StringBuilder();\n        Map<String, Character> hmap = new HashMap<>();\n        hmap.put("&quot;", \'"\');\n        hmap.put("&apos;", \'\\\'\');\n        hmap.put("&amp;", \'&\');\n        hmap.put("&gt;", \'>\');\n        hmap.put("&lt;", \'<\');\n        hmap.put("&frasl;", \'/\');\n        \n        int i = 0;\n        int n = text.length();\n        while(i < n){\n            // increament and keep adding to stringbuilder till we find \'&\'\n            while(i < n && text.charAt(i) != \'&\'){\n                res.append(text.charAt(i));\n                i++;\n            }\n            \n            // looking for \';\' to form a substring ("&....;") and check if it is a valid HTML entity\n            int start = i; // i is at \'&\'\n            while(i < n && text.charAt(i) != \';\'){\n                i++;\n            }\n            \n            // check if we reached the end of text, because i will be on index n\n            // and code will break in the next statement when taking the substring \n            if(i >= n) break;\n            \n            String entity = text.substring(start, i+1);\n            if(hmap.containsKey(entity)){\n                res.append(hmap.get(entity));\n            }\n            else{\n                res.append(entity);\n            }\n            i++;\n        }\n        return res.toString();\n    }\n}\n```
[]