Paste a multi-line Java String in Eclipse

Thilo picture Thilo · Jan 29, 2010 · Viewed 108.6k times · Source

Unfortunately, Java has no syntax for multi-line string literals. No problem if the IDE makes it easy to work with constructs like

  String x = "CREATE TABLE TEST ( \n"
             + "A INTEGER NOT NULL PRIMARY KEY, \n"
            ...

What is the fastest way to paste a multi-line String from the clipboard into Java source using Eclipse (in a way that it automatically creates code like the above).

Answer

Thilo picture Thilo · Jan 29, 2010

Okay, I just found the answer (on Stackoverflow, no less).

Eclipse has an option so that copy-paste of multi-line text into String literals will result in quoted newlines:

Preferences/Java/Editor/Typing/ "Escape text when pasting into a string literal"