# Replacing a local variable with a query

To replace a local variable with a query:

- In the Java editor, select the expression with which the local variable is initialized
- Invoke the Extract Method refactoring by either:
  - Selecting Refactor > Extract Method from the editor's pop-up menu or
  - Selecting Refactor > Extract Method from the menu bar
- Perform the Extract Method refactoring
- Select the local variable (or a reference to it)
- Invoke the Inline Local Variable by either:
  - Selecting Refactor > Inline from the editor's pop-up menu or
  - Selecting Refactor > Inline from the menu bar
- Perform the Inline Local Variable refactoring

Java development tools (JDT)

Extracting a method
Inlining a local variable

Refactoring actions
Refactoring dialogs
Java preferences