Here you can find the source of hashCode(List> list)
Parameter | Description |
---|---|
list | the list |
public static int hashCode(List<?> list)
//package com.java2s; import java.util.List; import java.util.Set; public class Main { /**// www . ja v a 2s. com * Computes the hash code for a list per the contract defined by {@link List#hashCode()}. * * @param list the list * @return the hash code for {@code list} */ public static int hashCode(List<?> list) { return listHashCode(list); } /** * Computes the hash code for a set per the contract defined by {@link Set#hashCode()}. * * @param set the set * @return the hash code for {@code list} */ public static int hashCode(Set<?> set) { int hashCode = 0; for (Object item : set) { if (item != null) { // don't overflow stack if set contains itself -- substitute default hashcode hashCode += item == set ? System.identityHashCode(set) : item.hashCode(); } } return hashCode; } private static int listHashCode(Iterable<?> l) { int ret = 1; for (Object e : l) { // don't overflow stack if list contains itself -- substitute default hashcode int elementHash = e == l ? System.identityHashCode(l) : (e == null ? 0 : e.hashCode()); ret = 31 * ret + elementHash; } return ret; } }