Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Map<Character, String> HTML_ESCAPE_CHARACTERS = new HashMap<Character, String>();

    public static String escape(String str) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            String escaped = HTML_ESCAPE_CHARACTERS.get(c);
            if (escaped == null) {
                result.append(c);
            } else {
                result.append(escaped);
            }
        }
        return result.toString();
    }
}