Scala data types (bit sizes, ranges, and docs)

Scala FAQ: What are the Scala data types? How many bits do they use to store their data, and what is the range of those data types?

Courtesy of the excellent book, Programming in Scala, here is a list and description of the Scala data types, including bit sizes and data ranges:

Data Type     Definition

Boolean       true or false

Byte          8-bit signed two's complement integer (-2^7 to 2^7-1, inclusive)
Short         16-bit signed two's complement integer (-2^15 to 2^15-1, inclusive)
Int           32-bit two's complement integer (-2^31 to 2^31-1, inclusive)
Long          64-bit two's complement integer (-2^63 to 2^63-1, inclusive)

Float         32-bit IEEE 754 single-precision float
Double        64-bit IEEE 754 double-precision float

Char          16-bit unsigned Unicode character (0 to 2^16-1, inclusive)
String        a sequence of Chars

Notes about Scala data types

The String class resides in the package java.lang, and all these other types are in the package scala.

You may have noticed that these data types in Scala have the exact same range as the corresponding data types in Java. This makes it easy to convert these Scala types to their corresponding Java primitive types.

Also interesting to note, if you're into specifics: Collectively, Byte, Short, Int, Long, and Char are called integral types. The integral types plus Float and Double are called numeric types. (That was again courtesy of the book, Programming in Scala.)

Official Scala data type documentation

Here are links to the official Scala docs for these data types:

And here's a link to the Programming in Scala book on Amazon:

Post new comment

The content of this field is kept private and will not be shown publicly.