Java - Write code to escape Quotes in a string

Requirements

Write code to escape Quotes

\ becomes \\.

Hint

You can use the replace method to escape string.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com\"";
        System.out.println(escapeQuotes(s));
    }//from   w  ww . j av a  2  s.  c  om

    public static String escapeQuotes(String s) {
        s = s.replace("\\", "\\\\");
        s = s.replace("\"", "\\\"");

        return s;
    }
}

Related Exercise