Skip to content

Latest commit

 

History

History
29 lines (27 loc) · 995 Bytes

File metadata and controls

29 lines (27 loc) · 995 Bytes
public String encode(List<String> strs) {
    StringBuilder sb = new StringBuilder();
    for (String str : strs) {
        sb.append(str.replace("%", "%25").replace(",", "%2C")).append(",");
    }
    return sb.length() > 0 ? sb.toString() : "";
}

public List<String> decode(String str) {
    List<String> decodedList = new ArrayList<>();
    if (str.length() > 0) {
        int commaIndex = str.indexOf(",");
        while (commaIndex > -1) {
            decodedList.add(str.substring(0, commaIndex).replace("%2C", ",").replace("%25", "%"));
            str = str.substring(commaIndex + 1);
            commaIndex = str.indexOf(",");
        }
    }
    return decodedList;
}