In c#, @ sign is used before string literals to change how the compiler parses the string. Is there a counterpart of this in java? Using concatenation confuses me sometimes.
Asked
Active
Viewed 72 times
0
-
1You can use `Pattern.quote` and Java will quote everything for you. – Maroun Dec 16 '14 at 08:53
-
1@MarounMaroun Would be better to add it as an answer? :\ – Soner Gönül Dec 16 '14 at 08:59
-
i want something like this. `String str = "I am a kid ";` after a is next line and java like c# by using @ will still accept that code. – Rjmr Dec 16 '14 at 08:59
-
oh man, java still doesn't have this feature. but anyways, thanks for the help. – Rjmr Dec 16 '14 at 09:03
1 Answers
0
Strings cannot be on multiple lines in java. Your editor may automatically wrap them, but the string itself cannot be on multiple lines - that is, don't hit enter in the middle of a string literal.
If you want your string to contain a new line, use \n ex
System.out.println("Line 1\nLine 2");
results in
Line 1
Line 2

Jon Takagi
- 101
- 3
-
thanks for the advice dude. but what i wanted in my program is that i don't want any + signs because sometimes it confuses me and i hit enter in the middle of the string literal. – Rjmr Dec 16 '14 at 09:10
-
ah. Java can't really deal with that without concatenating them, like you said. – Jon Takagi Dec 16 '14 at 09:12
-