<html><head><link rel="canonical" href="https://www.jetbrains.com/help/idea/find-and-replace-code-duplicates.html.md/" data-react-helmet="true"/></head><body># Find and replace code duplicates

The Find and Replace Code Duplicates action lets you find code repetitions similar to the selected method or constant field, and replace them with calls to the original method or constant. It also lets you specify a scope for your search.

Procedure:

1. Place the caret within the method or a constant field whose duplicates you want to search for.

2. From the main or context menu, select `Refactor | Find and Replace Code Duplicates`.

3. In the dialog that opens, select the scope where IntelliJ&nbsp;IDEA should look for code duplicates.

4. For each found code duplicate, IntelliJ&nbsp;IDEA will prompt you to confirm the replacement.

## Example

| Before | After |
| --- | --- |
|     ```JAVA 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; } ```    |     ```JAVA 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; } ```    |

</body></html>