javastringquotesescaping

How to enter quotes in a Java string?


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

String value = " "ROM" ";

but that doesn't work. How can I include "s within a string?


Solution

  • In Java, you can escape quotes with \:

    String value = " \"ROM\" ";