Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala
communitycreator

What is toIntExact() in scala?

Hammad Nasir

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.

The toIntExact() function in Scala is a function in the math package that returns the integer value of the argument passed.

Syntax


def toIntExact(x: Long): Int

Parameters

The function takes in one parameter x. The argument is of the Long type.

Return value

The function returns the integer value of x.


The function throws an ArithmeticException if x overflows an integer.

Code

object MainObject {
def main(args: Array[String]) {
var val1 : Long = 100;
var val2 : Long = 12;
println("Math.toIntExact(val1) = " + Math.toIntExact(val1));
println("Math.toIntExact(val2) = " + Math.toIntExact(val2));
}
}

RELATED TAGS

scala
communitycreator

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