How to enter quotes in a Java string?

jimmy picture jimmy · Aug 24, 2010 · Viewed 458.1k times · Source

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?

Answer

Ian Henry picture Ian Henry · Aug 24, 2010

In Java, you can escape quotes with \:

String value = " \"ROM\" ";