How to select duplicate values from a list in java?

后端 未结 13 827
傲寒
傲寒 2021-01-18 00:38

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

13条回答
  •  囚心锁ツ
    2021-01-18 01:23

    Have a

    Map numberToOccurance = new HashMap();
    

    maintain count and number, at the end iterate keyset and get values with more than one count

提交回复
热议问题