Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Created February 3, 2022 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/e94b1100932db2c02b18eb11afc56079 to your computer and use it in GitHub Desktop.
Save JamoCA/e94b1100932db2c02b18eb11afc56079 to your computer and use it in GitHub Desktop.
Sample CFML to hash a string into an integer using java hashCode() using ColdFusion.
<!--- 20220203 string.hashCode() returns an integer.
GIST: https://gist.github.com/JamoCA/e94b1100932db2c02b18eb11afc56079
INFO: https://www.programiz.com/java-programming/library/string/hashcode
--->
<cfscript>
tests = [
"hello world"
,now()
,"abcdefghijklmnopqrstuvwxyz"
,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
,123
];
results = createObject( "java", "java.util.Hashtable" ).init();
for (test in tests) {
results["#test#"] = test.toString().hashCode();
}
writedump(var=results, label="hashCode() results");
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment