In Java, should I escape a single quotation mark (') in String (double quoted)?

后端 未结 2 614
心在旅途
心在旅途 2020-12-14 00:54

In Java, \\\' denotes a single quotation mark (single quote) character, and \\\" denotes a double quotation mark (double quote) character.

2条回答
  •  失恋的感觉
    2020-12-14 01:34

    It's best practice only to escape the quotes when you need to - if you can get away without escaping it, then do!

    The only times you should need to escape are when trying to put " inside a string, or ' in a character:

    String quotes = "He said \"Hello, World!\"";
    char quote = '\'';
    

提交回复
热议问题