Remove braces

It is permissible to remove braces in case they are superfluous. This not only applies to the control statements if, for, while and do-while, but also to every block in general (remember a block is just a sequence of statements, local class declarations and local variable declaration statements within braces).

Note that the insert and remove braces options are mutually exclusive.

if..else

When enabled, braces around the body of if...else statements are removed when possible.

Example 2.57. Brace removal for if statements

if (true) {
    break;
} else {
    return;
}

would become

if (true)
    break;
else
    return;
for

When enabled, braces around the body of for statements are removed when possible.

Example 2.58. Brace removal of for statements

for (int i = 0; i < count; i++) {
    System.out.println(i);
}

would become

for (int i = 0; i < count; i++)
    System.out.println(i);
while

When enabled, braces around the body of while statements are removed when possible.

Example 2.59. Brace removal for while statements

while (!isDone) {
    doSomething();
}

would become

while (!isDone)
    doSomething();
do...while

When enabled, braces around the body of do...while statements are removed when possible.

Example 2.60. Brace removal for do...while statements

do {
  something();
} while (condition);

would become

do
  something();
while (condition);
switch

When enabled, braces are removed around the body of labeled statements inside switch blocks when possible.

Since 1.8

Example 2.61. Brace removal for switch

switch (c) {
    case 'a':
    case 'b': {
        System.out.println();
        break;
    }
}

would become

switch (c) {
    case 'a':
    case 'b':
        System.out.println();
        break;
}
Blocks

When enabled, arbitrary block braces are removed when possible.

Example 2.62. Brace removal for blocks

{
    System.out.println();
}

would become

System.out.println();