How to enter quotes in a Java string?

后端 未结 10 1166
不知归路
不知归路 2020-11-22 05:38

I want to initialize a String in Java, but that string needs to include quotes; for example: \"ROM\". I tried doing:

String value = \" \"ROM\" \         


        
10条回答
  •  被撕碎了的回忆
    2020-11-22 06:21

    Look into this one ... call from anywhere you want.

    public String setdoubleQuote(String myText) {
        String quoteText = "";
        if (!myText.isEmpty()) {
            quoteText = "\"" + myText + "\"";
        }
        return quoteText;
    }
    

    apply double quotes to non empty dynamic string. Hope this is helpful.

提交回复
热议问题