Data Types in Scala - GeeksforGeeks

08 May, 2020
A data type is a categorization of data which tells the compiler that which type of value a variable has. For example, if a variable has an int data type, then it holds numeric value. In Scala, the data types are similar to Java in terms of length and storage. In Scala, data types are treated same objects so the first letter of the data type is in capital letter.The data types that are available in Scala as shown in the below table:
Note: Scala does not contain the concept of primitive type like in Java.
For Example:
// Scala program to illustrate Datatypesobject Test{def main(args: Array[String]) {    var a: Boolean = true    var a1: Byte = 126    var a2: Float = 2.45673f    var a3: Int = 3    var a4: Short = 45    var a5: Double = 2.93846523    var a6: Char = 'A'    if (a == true)     {    println("boolean:geeksforgeeks")    }    println("byte:" + a1)    println("float:" + a2)    println("integer:" + a3)    println("short:" + a4)    println("double:" + a5)    println("char:" + a6)}}
Output:
boolean:geeksforgeeks
byte:126
float:2.45673
integer:3
short:45
double:2.93846523
char:A

Literals in Scala : Here we will discuss different types of literals used in Scala.
Integral Literal: These are generally of int type or long type (“L” or “I” suffix used ). Some legal integral literals are:020402130xFFFFFFFF0743LFloating-point Literals: These are of float type(“f” or”F” suffix used ) and of double type.0.71e60f3.12154f1.0e100.3Boolean Literals: These are of Boolean type and it contains only true and false.Symbol Literals: In Scala, symbol is a case class. In symbol literal, a’Y’ is identical to scala.Symbol(“Y”).package scalafinal case class Symbol private (name: String) {override def toString: String = “‘” + name}Character Literals: In Scala, character literal is a single character that is encircled between single quotes.There characters are printable unicode character and also described by the escape character. Few valid literals are shown below:‘\b’‘a’‘\r’‘\u0027’String Literals: In Scala, string literals are the sequence of character that are enclosed between double quotes. Some valid literals as shown below:“welcome to \n geeksforgeeks”“\\This is the tutorial of Scala\\”Null Values: In Scala, null value is of scale.Null type, that’s the way it is adaptable with every reference type. It is indicated as a reference value which refers to a special “null” object.Multi-line Literals: In Scala, multi-line literals are the sequence of characters that are encircled in between triple quotes. In this new line and other control characters are valid. Some valid multi-line literals shown below:“””welcome to geeksforgeeks\nthis is the tutorial of \nscala programing language”””
020402130xFFFFFFFF0743L
Floating-point Literals: These are of float type(“f” or”F” suffix used ) and of double type.0.71e60f3.12154f1.0e100.3
0.71e60f3.12154f1.0e100.3
Boolean Literals: These are of Boolean type and it contains only true and false.
Symbol Literals: In Scala, symbol is a case class. In symbol literal, a’Y’ is identical to scala.Symbol(“Y”).package scalafinal case class Symbol private (name: String) {override def toString: String = “‘” + name}
package scalafinal case class Symbol private (name: String) {override def toString: String = “‘” + name}
Character Literals: In Scala, character literal is a single character that is encircled between single quotes.There characters are printable unicode character and also described by the escape character. Few valid literals are shown below:‘\b’‘a’‘\r’‘\u0027’
‘\b’‘a’‘\r’‘\u0027’
String Literals: In Scala, string literals are the sequence of character that are enclosed between double quotes. Some valid literals as shown below:“welcome to \n geeksforgeeks”“\\This is the tutorial of Scala\\”
“welcome to \n geeksforgeeks”“\\This is the tutorial of Scala\\”
Null Values: In Scala, null value is of scale.Null type, that’s the way it is adaptable with every reference type. It is indicated as a reference value which refers to a special “null” object.
Multi-line Literals: In Scala, multi-line literals are the sequence of characters that are encircled in between triple quotes. In this new line and other control characters are valid. Some valid multi-line literals shown below:“””welcome to geeksforgeeks\nthis is the tutorial of \nscala programing language”””
“””welcome to geeksforgeeks\nthis is the tutorial of \nscala programing language”””
ManasChhabra2
Scala
Scala-Basics
Scala
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
For Loop in Scala
Scala | map() method
Scala | flatMap Method
Scala | reduce() Function
Scala List filter() method with example
String concatenation in Scala
Scala Tutorial – Learn Scala with Step By Step Guide
Type Casting in Scala
How to get the first element of List in Scala
Scala List contains() method with example