whydoesthiscodegiveanegativehashcode?
import java.util.HashSet;
import java.util.Set;
公共类ab {
//*
字符串单身网络args )。
string S1=' operationsonadynamicsetcanbegroupedintotwocategoriesqueries,whichsimplyreturninformationabouttheset,and modifynamichet whichchangetheset.hereisalistoftypicaloperationspecificapplicationwillusuallyrequireonlyafewofthesetobeimplementedsomed thekeysaredrawnfromatotallyordere,such as the real numbers, orthesetofallwordsundertheusualalphabeticordering.atotalorderingallowsustodefinetheminimumelementoftheset,for example, ortospeakofthenextelementlargerthanagivenelementinaset.operationsondynamicsetcanbegroupedintotwocatected
String s2='abc ';
}
}
thestringclassoverrideshashcode (toproducedeterministicresults.theresulthasnothingtodowithmemoryaddreses.the string.he she
thehashcodeforastringobjectiscomputedas
s [0] * 31 ^ [ n-1 ] S1 * 31 ^ [ n-2 ] . s [ n-1 ]
using int arithmetic,wheres [ I ] istheithcharacterofthestring,n is the length of the string,and^Indicatesexponentiation.(
notethatforevenrelativelyshortstringsthevaluecangettoobigforaninteger.duringthecalculations,wheneveranoverflowocursonlythythettttheger
At the end of the calculation,ifthemostsignificantbitoftheresultingintegerissettheintegerisnegative,if not then positive。