Archive

Posts Tagged ‘duplicated elements’

Remove duplicated elements, Array JavaScript

March 20, 2013 1 comment

I got this piece of code from stackoverflow, and im just sharing this cus this is something that I am usually looking for :P and this will save some time :), I am adding the source if you want to check out more options on how to do this.


function getDistinctArray(a) {
var d = {};
return a.filter(function(e) {
var h = e.valueOf(), i = d[h];
d[h] = true;
return !i;
});
}

Source

Advertisements

Conocer si una lista tiene elementos duplicados/repetidos en Java

November 18, 2010 Leave a comment

Les dejo este método generico para java 5 en adelante que regresa verdadero si la lista contiene elementos repetidos.

public static <T> boolean tieneElementosDuplicados(List<T> lista){

return new HashSet<T>(lista).size() != lista.size();

}

Categories: Java, Mini-tips, Programación