ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Scala String hashCode() Method with Example

Here, we will learn about the hashCode() method of String class in Scala. It is used to find the hash code for the given string. We will see its working, syntax and example.
Submitted by Shivang Yadav, on February 03, 2021

String is an immutable collection that stores sequences of characters.

String hashCode() Method

The hashCode() method on strings is used to return the hash code for the given string in Scala.

Syntax:

string_Name.hashCode()

Parameters: The method is a parameter-less method i.e. it does not accept any parameter.

Return Value: It returns an integer which is the hash code for the given string in Scala.

Example 1:

object myObject {
    def main(args: Array[String]) {
        val string1 = "scala"
        val hash = string1.hashCode()
    
        println("The hash code for the string is " + hash)
    }
}

Output:

The hash code for the string is 109250886
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.