Java Utililty Methods Collection Hash

List of utility methods to do Collection Hash

Description

The list of methods to do Collection Hash are organized into topic(s).

Method

inthashCode(Collection c)
Computes a hash code over c independent of the underlying Collection implementation.
int[] codes = new int[c.size()];
Iterator itr = c.iterator();
int i = 0;
while (itr.hasNext()) {
    codes[i++] = itr.next().hashCode();
Arrays.sort(codes);
int prime = 53;
...
inthashCode(Collection collection)
Method hashCode.
int hashCode = 1;
Iterator<E> i = collection.iterator();
while (i.hasNext()) {
    E obj = i.next();
    hashCode = (31 * hashCode) + (obj == null ? 0 : obj.hashCode());
return hashCode;
inthashCode(Collection collection)
Calculates the hash code for a given collection including the order of elements
final int prime = 31;
int result = 1;
if (collection != null) {
    Iterator<E> iterator = collection.iterator();
    while (iterator.hasNext()) {
        E next = iterator.next();
        result = prime * result + (next != null ? next.hashCode() : 0);
return result;
inthashCodeDeep(Collection collection)
Calculates the hashCode of a collection by summing up the hashcodes of all its members.
int hashCode = 0;
for (Object o : collection) {
    hashCode += o.hashCode();
return hashCode;
inthashCodeUnordered(Collection collection)
Calculates the hash code for a given collection not including the order of elements.
int result = 1;
if (collection != null) {
    Iterator<E> iterator = collection.iterator();
    while (iterator.hasNext()) {
        E next = iterator.next();
        result = result * (next != null ? next.hashCode() : 0);
return result;