JAVA Hashmap Solution and One Line Code Solution
Approach 1: HashMap\n\nclass Solution {\n    public String entityParser(String text) {\n        \n        HashMap<String, String> map = new HashMap<String, Stri
**Approach 1: HashMap**\n```\nclass Solution {\n    public String entityParser(String text) {\n        \n        HashMap<String, String> map = new HashMap<String, String>();\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        StringBuffer sb = new StringBuffer();\n        for(int i = 0; i < text.length(); i++) {\n            char ch = text.charAt(i);\n            if(ch == \'&\') {\n                for(int j = i + 1; j < text.length(); j++) \n                    if(text.charAt(j) == \';\') {\n                        String s = text.substring(i, j + 1);\n                        if(map.containsKey(s)) sb.append(map.get(s));\n                        else sb.append(s);\n                        i = j;\n                        break;\n                    }\n            }\n            else {\n                sb.append(ch);\n            }\n        }\n        \n        return sb.toString();\n    }\n}\n```\n\n### **Approach 2: One Line Code** \n\n```\nclass Solution {\n    public String entityParser(String text) {\n        \n        return text.replace("&quot;", "\\"").replace("&apos;", "\'").replace("&gt;", ">").replace("&lt;", "<").replace("&frasl;", "/").replace("&amp;", "&");\n    }\n}\n```\n\n\nPlease help to **UPVOTE** if this post is useful for you.\nIf you have any questions, feel free to comment below.\n**HAPPY CODING :)\nLOVE CODING :)**\n
[]