Example array: [1,2,3,4,4,5,6,7,12,13,7,4]

I want to keep only values which has more than one. Thus final outcome I am expecting is [4,4,4,7,7]

I could find duplicates as follows. But how can I reverse this? Any guidance is appreciated. Thank you.

```
for (int i = 0; i < names.length; i++) { 
    for (int j = i + 1; j < names.length; j++) { 
        if (names[i].equals(names[j]) ) { 
            // got the duplicate element 
        } 
    } 
}

```