Example
| Before | After |
|---|---|
public void method() { int a = 1; int b = 2; int c = a+b; int d = b+c; } ... private int add(int a, int b) { return a+b; } |
public void method() { int a = 1; int b = 2; int c = add(a,b); int d = add(b,c); } ... private int add(int a, int b) { return a+b; } |
- Position the cursor within the method, duplicates of which you want to search for.
- Do one of the following to open the Replace Method Code Duplicates dialog box:
- On the menu, choose .
- On the context menu, choose .
- Press the Replace button to continue. For each code fragment found, IntelliJ IDEA will prompt you to confirm replacement.

