?
Solved

java concatenation and special characters

Posted on 2011-03-16
2
Medium Priority
?
408 Views
Last Modified: 2012-05-11
a,b,c are variables.
And I want to concatenate them. So I have two related questions:

1- If I do the following, is it gonna process "\n" as a new line character or literally \n? If literally \n, then how can I make it processed as new line character?

2- So I have variable a in my hand. And I want to add b and c as a prefix to a not a suffix. I mean in the beginning of what is in a now. Is this gonna work? If not how can I make it?

a = b + "\n" + c + a;

Open in new window

0
Comment
Question by:Tolgar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 35152114
That newline will be interpreted as an escape sequence so you'll actually get a newline in the String. Print it out and you'll see
0
 
LVL 92

Expert Comment

by:objects
ID: 35152137
1. It will be treated as a new line char. Generally better to use System.getProperty("line.separator") as it will be line seperator for the platform you are running on
2. you can change the order of concatentation however you like
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question