[英]shuffle arraylist without duplicates
I want to shuffle an arraylist in java but using this creates duplicates : java.util.Collections.shuffle(this.OrderedCustomers);
我想在java java.util.Collections.shuffle(this.OrderedCustomers);
一个arraylist但是使用它会创建重复项: java.util.Collections.shuffle(this.OrderedCustomers);
Here, this.OrderedCustomers is an array list. 这里,this.OrderedCustomers是一个数组列表。 Thanks for your help ! 谢谢你的帮助 !
The Collections.shuffle
method will shuffle the elements in the given list. Collections.shuffle
方法将随机播放给定列表中的元素。 So if that list contains duplicates, so will the shuffled one. 因此,如果该列表包含重复项,那么将进行重复调整。 Add your objects to a set (assuming they implement hashCode
and equals
!) to remove duplicates first and then to a list and finally to the shuffle method. 将对象添加到集合中(假设它们实现hashCode
和equals
!)首先删除重复项,然后删除列表,最后删除shuffle方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.