Java String contains()
Java String contains() method to check if a String contains a specified character sequence. This method returns a boolean datatype which is a result in testing if the String contains the characters specified on the method argument in CharSequence object type. The contains() method returns true if and only if this string contains the specified sequence of char values.
In the Java programming language, every class implicitly or explicitly provides a hashCode() method, which digests the data stored in an instance of the class into a single hash value (a 32-bit signed integer). The String hashCode value of a Java String is computed as:
- It is fast, to the extent that it probably produces hashes as the CPU can read the String from memory (i.e. you usually can't get better without skipping large parts of the String). It does just one multiply and one add per character in the String.
- For typical sets of random Strings, it produces well-distributed hashes over the entire int range.
It is important to note that it is not a cryptographic hash function, its only obligation is to obey the contract defined by java.lang.Object , So don't use it for that. Moreover, be aware that you likely will get hash collisions as it is producing a 32-bit hash. So you just need to design your algorithms to take that into account.