On Mon, Aug 20, 2012 at 11:11 AM, Gero <
geronim...@gmail.com> wrote:
> Hi,
> How can i delete duplicates in my list? Why is there no list.duplicate(); or
> list.unique()?
Removing duplicates isn't uniquely defined in a list: Which element is
retained - the first or the last (or a middle one if more than two)?
I'd write it myself to fit whatever strategy I want:
// Retains first instance of element in list.
function dedup(List list) {
Set seen = new Set();
int unique = 0;
for (int i = 0; i < list.length; i++) {
var element = list[i];
if (!seen.contains(element)) {
seen.add(element);
list[unique++] = element;
}
list.length = unique;
True. There is no LinkedHashSet. You could use a LinkedHashMap
instead, and the iterate the keys, but that's more complicated.
/L
--
Lasse R.H. Nielsen
l...@google.com
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K -
Denmark - CVR nr. 28 86 69 84