Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

Managing Automatic Insertion of Closing Characters

When typing in the Source Editor, one of the first things that you will notice is that the closing characters are automatically inserted when you type the opening character. For example, if you type a quote mark, the closing quote mark is inserted at the end of the line. Likewise, parentheses(()), brackets ([]), and curly braces ({}) are completed for you.

While this might seem annoying at first, the feature was designed to not get in your way. If you type the closing character yourself, the automatically inserted character is overwritten. Also, you can end a line by typing a semicolon (;) to finish a statement. The semicolon is inserted at the end of the line after the automatically generated character or characters.

See the following subtopics for information on how to use the insertion of matching closing characters.

Finishing a Statement

When the Source Editor inserts matching characters at the end of the line, this would appear to force you to move the insertion point manually past the closing character before you can type the semicolon. In fact, you can just type the semicolon without moving the insertion point, and it will be placed at the end of the line automatically.

For example, to get the line

ArrayList ls = new ArrayList();

you would only have to type

ArrayList ls = new ArrayList(;

Splitting a String Between Two Lines

If you have a long string that you want to split between two lines, the Source Editor adds the syntax for concatenating the string when you press Enter.

For example, to get the lines

String s = "Though typing can seem tedious, reading long" +
"and convoluted sentences can be even worse."

you could type

String s = "Though typing can seem tedious, reading long
and convoluted sentences can be even worse.

The final three quote marks and the plus sign (+) are added for you.

If you want to break the line without creating the concatenation, press Shift-Enter.

  • + Share This
  • 🔖 Save To Your Account