Storing arrays in Set and avoiding duplicates

前端 未结 5 1750
你的背包
你的背包 2020-12-24 06:09
HashSet boog = new HashSet();
boog.add(new String[]{\"a\", \"b\", \"c\"});
boog.add(new String[]{\"a\", \"b\", \"c\"});
boog.add(new          


        
5条回答
  •  一生所求
    2020-12-24 06:38

    You can't. arrays use the default identity-based Object.hashCode() implementation and there's no way you can override that. Don't use Arrays as keys in a HashMap / HashSet!

    Use a Set of Lists instead.

提交回复
热议问题