concatenation : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

concatenation
Concatenation means gluing Strings end to end to form one big String. You specify it in Java with the + operator (the same as used for addition), e. g.
// simple concatenation
final String greeting = "Happy" + " " + "birthday.";

Javac does concatenation of String literals, such as in the example above, at compile time, so they have no run-time overhead.

Javac implements concatenation with calls to StringBuffer in JDK (Java Development Kit) 1.4- and StringBuilder in 1.5+. These are not as efficient as using StringBuilder directly since there is no way to specify the size of the buffer.

Alternate Concatenation Techniques

Concatenating Files Programmatically

You can concatenate files programmatically by reading the pieces and writing them out in one big file. There a few things to be aware of:

Concatenating Files at the Command Prompt

You can concatenate files at the command prompt (or my execing a command processor with copy commands.) To glue three files together to form d.txt you would type:
Rem glue a.txt, b.txt and c.txt into a new file d.txt
Rem leaving a.txt, b.txt and c.txt as they were.
copy a.txt + b.txt + c.txt  d.txt
copy /A warns copy that the files might have EOL characters.
copy /B tells copy to treat any EOL characters like ordinary data.

Take Command does not support these options. It presumes text files do not use obsolete EOL characters.

It is safe to append onto your target like this:

However,

Learning More

Oracle’s Javadoc on StringBuffer class : available:
Oracle’s Javadoc on StringBuilder class : available:
Oracle’s Javadoc on StringWriter class : available:
Oracle’s Javadoc on CharArrayWriter class : available:

This page is posted
on the web at:

http://mindprod.com/jgloss/concatenation.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\concatenation.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.191.68.112]
You are visitor number