Java Code Formatter: Re-indent Classes and Methods

Fixes indentation, blank lines and optionally line breaks in Java code without sending it anywhere.

Use the tool

Why this tool exists

Messy indentation hides the structure of Java code, and minified or copy-pasted code is worse. A re-indenter gives you the block layout back quickly.

The tool reads your code with a small scanner that knows strings, comments and raw literals, so braces inside them are ignored. It then sets the indent from bracket depth and, if you ask, puts a line break after braces and semicolons. It is not google-java-format.

How to use it

  1. Paste Java code.
  2. Pick the indent and line break mode.
  3. Copy the result.
  4. Use your build's formatter for team style.

Frequently asked questions

Is this the same as google-java-format?

No. Formatters such as google-java-format also wrap lines and sort imports. This tool re-indents and optionally breaks lines only.

Will it change what my code does?

It only changes whitespace outside strings, comments and raw literals. Test results: the non-whitespace text was unchanged on all test files, and re-running the tool gave the same output. Review the diff anyway.

Why not wrap long lines?

Wrapping needs a full parser. This tool does not have one.

Is my input sent anywhere?

No. Everything runs in your browser and nothing is uploaded.