When and why you may want to use code formatting

Introduction to Reformatting

Generally when you're coding you don't need to manually format your code, IntelliJ IDEA does its best to do the right thing automatically. For example, if you press Enter, your caret goes into the correct place for you to start typing. The same applies if we use other shortcuts like ⇧⏎ (macOS), Alt+Enter (Windows/Linux) to move to the next line, or use code generation. IntelliJ IDEA will also reformat code that you paste into the IDE according to your code style settings.

Reformatting a Selection or Class

However, sometimes you will want to reformat a portion of code in your class, the whole class, or a whole package. You may want to reformat manually or when you commit your code. Let's take a look at how you can reformat a selection or class manually in the next step.