The Extract Constant refactoring makes your source code easier to read and maintain. It also helps you avoid using hardcoded constants without any explanations about their values or purpose.
In the editor, select an expression or declaration of a variable you want to replace with a constant.
- Press Ctrl+Alt+C to introduce a constant or select
Select a name from a list that opens or type your own name and press Enter..
If you press Ctrl+Alt+C twice, the Extract Constant dialog opens.
Specify additional options for the constant, for example, change its visibility, or move the constant to another class.
Let's introduce a constant for the expression "string" that occurs twice throughout code.