Linked Questions
40 questions linked to/from Does Java have support for multiline strings?
23
votes
1
answer
17k
views
Is there heredoc alternative in Java (heredoc as PHP)? [duplicate]
For JAVA development I need writing to a files with strings like "\r\t\n <>", because from Java I want writing a PHP file. If you can't understand look at this example:
BufferedWriter buffW = new ...
10
votes
2
answers
14k
views
Working with long strings (heredocs) in Java - the readable approach? [duplicate]
I need to work with long strings containing line breaks in Java. Those are for HTML generation, but it is not the most important here.
I'm aware Java is cripple in a way it doesn't have heredocs. But ...
-1
votes
1
answer
8k
views
How to break a string literal across multiple lines of source code in Java? [duplicate]
I have done C++ in the past and to continue with a long line of code I would use the:
\
operator. My compiler does not seem to recognize that in Java (obviously). What command do I use for next line ...
-2
votes
1
answer
4k
views
How to create multiline strings in Java? [duplicate]
I know scala use stripMargin to create multiline,such as:
def catalog = s"""{
|"table":{"namespace":"default", "name":"table1"},...
0
votes
1
answer
833
views
How to assign json string contents and keep formatting? [duplicate]
I have a block of json that I want to initialize a string with and I want to keep the formatting but this doesn't work.
The json will be much larger than this but just looking for possibilities for ...
-1
votes
1
answer
144
views
Combining println in Java [duplicate]
I'm using multiple + in the code. I want to know if there is any other way to do so without using + many times.
package java;
import java.util.Scanner;
public class Calculator
{
public static void ...
7
votes
0
answers
72
views
C# @ line break functionality equivalent in Java [duplicate]
In C#, you can use verbatim string literals so that you don't have to include '+' sign to concatenate strings on multiple lines. For example:
var fooStr = @"This is a foo string.
It ...
-1
votes
1
answer
33
views
How can i correct the syntax of update query with join in mysql? [duplicate]
int i=st.executeUpdate("update tbl_loginprogrammer1
JOIN tbl_loginprogrammer
ON tbl_loginprogrammer1.pid = tbl_loginprogrammer.proid
SET tbl_loginprogrammer1....
746
votes
23
answers
632k
views
Java: convert List<String> to a join()d String
JavaScript has Array.join()
js>["Bill","Bob","Steve"].join(" and ")
Bill and Bob and Steve
Does Java have anything like this? I know I can cobble something ...
223
votes
6
answers
116k
views
Paste a multi-line Java String in Eclipse [duplicate]
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 ...
70
votes
9
answers
148k
views
String concatenation in Java - when to use +, StringBuilder and concat [duplicate]
When should we use + for concatenation of strings, when is StringBuilder preferred and When is it suitable to use concat.
I've heard StringBuilder is preferable for concatenation within loops. Why is ...
48
votes
3
answers
42k
views
Compile and execute a JDK preview feature with Maven
With JDK/12 EarlyAccess Build 10, the JEP-325 Switch Expressions has been integrated as a preview feature in the JDK. A sample code for the expressions (as in the JEP as well):
Scanner scanner = new ...
36
votes
4
answers
31k
views
Surround with quotation marks
How is it possible in Eclipse JDT to convert a multiline selection to String. Like the following
From:
xxxx
yyyy
zzz
To:
"xxxx " +
"yyyy " +
"zzz"
I tried the following template
"${line_selection}...
29
votes
2
answers
42k
views
Format Json Strings intellij?
I am developing Java using intellij idea. And I want to assign a json like format to a Java String. But I am tired with escape characters that I have to deal with.
Is there any easy tool to format ...
24
votes
6
answers
6k
views
Simple/Direct/Heredoc way of constructing a HTML string in Java
In python I can construct a HTML string without worrying about escaping special characters like < or " by simply enclosing the string in triple quotes like:
html_string = """
<html>
<body&...