Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

hashcode
scala

What is hashCode method in Scala?

Sarvech Qadir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

We can use the hashCode() method is used to calculate the hash valuea uniquely identified numerical value. of the stated string or a given integer.

Method definition

def hashCode(): Int

Syntax

  • Integer value:
int.hashCode()
  • String value:
String.hashCode()

Calling this method returns an integer value which is the hashCode of the specified string/integer.

hashCode of an integer may be equal to the integer itself.

Code

Let’s have a look at a coding example to understand it further:

object Main extends App {
// string hashcode
val result = "Hello".hashCode()
println(result)
// integer hashcode
val result1 = 123.hashCode()
println(result1)
}

RELATED TAGS

hashcode
scala

CONTRIBUTOR

Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring