# Extract field

> **TL;DR**
> `Refactor | Extract/Introduce | Field`
>
>
>
> `Ctrl+Alt+F` (Windows), `⌘ ⌥ F` (macOS), `⌘ ⌥ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ F` (macOS System Shortcuts), `Ctrl+Alt+F` (XWin), `Ctrl+Alt+F` (GNOME), `Ctrl+Alt+F` (KDE), `Ctrl+Alt+F` (Emacs), `Ctrl+Alt+F` (Sublime Text), `Ctrl+Alt+F` (Sublime Text (macOS)), `Alt+Shift+E` (NetBeans), `Ctrl+R, F` (Visual Studio), `⌘ R, F` (Visual Studio (macOS)), `Ctrl+Alt+F` (Eclipse), `⌘ ⌥ F` (Eclipse (macOS))

The Extract Field refactoring lets you declare a new field and initialize it with the selected expression. The original expression is replaced with the usage of the field.

Procedure: Extract a field in place

1. Place the caret within a piece of code you want to extract into a field.

2. Press `Ctrl+Alt+F` (Windows), `⌘ ⌥ F` (macOS), `⌘ ⌥ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ F` (macOS System Shortcuts), `Ctrl+Alt+F` (XWin), `Ctrl+Alt+F` (GNOME), `Ctrl+Alt+F` (KDE), `Ctrl+Alt+F` (Emacs), `Ctrl+Alt+F` (Sublime Text), `Ctrl+Alt+F` (Sublime Text (macOS)), `Alt+Shift+E` (NetBeans), `Ctrl+R, F` (Visual Studio), `⌘ R, F` (Visual Studio (macOS)), `Ctrl+Alt+F` (Eclipse), `⌘ ⌥ F` (Eclipse (macOS)) or go to `Refactor | Extract/Introduce | Field` in the main menu.

3. Select an expression you want to introduce as a field.

![Select an expression](https://resources.jetbrains.com/help/img/idea/2026.2/extract_field.png)

If IntelliJ IDEA detects more than one occurrence in your code, it lets you specify which occurrences to replace.

![Extract multiple occurrences of a field](https://resources.jetbrains.com/help/img/idea/2026.2/extract_field_occurrences.png)

You can press `Ctrl+Alt+F` (Windows), `⌘ ⌥ F` (macOS), `⌘ ⌥ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ F` (macOS System Shortcuts), `Ctrl+Alt+F` (XWin), `Ctrl+Alt+F` (GNOME), `Ctrl+Alt+F` (KDE), `Ctrl+Alt+F` (Emacs), `Ctrl+Alt+F` (Sublime Text), `Ctrl+Alt+F` (Sublime Text (macOS)), `Alt+Shift+E` (NetBeans), `Ctrl+R, F` (Visual Studio), `⌘ R, F` (Visual Studio (macOS)), `Ctrl+Alt+F` (Eclipse), `⌘ ⌥ F` (Eclipse (macOS)) twice to open the Extract Field dialog where you can specify additional details, such as visibility options, or options for initializing your variable.

![Extract Field Dialog](https://resources.jetbrains.com/help/img/idea/2026.2/extract_field_dialog.png)

## Example

Let's extract the `anotherClass.intValue();` variable into a field. As a result, IntelliJ IDEA changes the selected variable name to `number` and declares it as the `private int number` field.

| Before | After |
| --- | --- |
|     ```JAVA public class Class {     AnotherClass anotherClass;     public void method() {         int a = 1;          int b = a + anotherClass.intValue();         int c = b + anotherClass.intValue();     } } ```    |     ```JAVA public class Class {     public AnotherClass anotherClass;     private int number;      public void method() {         int a = 1;         number = anotherClass.intValue();         int b = a + number;         int c = b + number;     } } ```    |

## See also

### Reference

[Extract Field Dialog](extract-field-dialog.html)

