Solved

java concatenation and special characters

Posted on 2011-03-16
2
401 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
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Why my table column Id is not passed to java object? 4 44
maven module vs maven project 3 47
Java basic valueOf question 1 29
Tagging and Merging on Branch 1 30
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

831 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