For example my list contains {4, 6, 6, 7, 7, 8} and I want final result = {6, 6, 7, 7}
One way is to loop through the list and eliminate unique values (4, 8 in this
Some good answers so far but another option just for the fun of it. Loop through the list trying to place each number into a Set e.g. a HashSet. If the add method returns false you know the number is a duplicate and should go into the duplicate list.
EDIT: Something like this should do it
Set unique = new HashSet<>();
List duplicates = new ArrayList<>();
for( Number n : inputList ) {
if( !unique.add( n ) ) {
duplicates.add( n );
}
}