Scala Tutorials


Scala File i/o: Open, Read and Write a File in Scala

1. Scala File i/o In this tutorial Scala File io, we will learn how to Open, read and write files in Scala. I also recommend you to go through the Scala Syntax and Scala Functions Articles to clear your basics on Scala. 2. Opening and Writing to a File We don’t have a class to write a file, in the Scala standard library, so we borrow java.io._ from Java. Or you could import java.io.File and java.io.PrintWriter. a. The Import C:\Users\lifei>cd […]


Learn Scala Map with Examples Quickly & Effectively

1. Scala Map We Have Already Studies Scala sets in our last tutorial. In this tutorial on Scala Map, we will see how to define and process maps, and what methods to call on them. We will learn to declare a Scala Map, Operations on a Map in Scala, Concatenating Maps, Printing Keys and Values from a Scala Map, Searching for a Key in a Map, Methods to Call on a Map etc. So lets begin… 2. An Introduction to […]


Scala Functions: Quick and Easy Tutorial

1. Functions in Scala In this tutorial, we will discuss some Scala Functions. After this article, you’ll be able to declare, define, and call your own functions in Scala. 2. An Introduction to Scala Functions When we want to execute a group of statements to perform a task a hundred times, we don’t type them a hundred times. We group them into a function, put a call to that function inside a loop, and make that loop run a hundred […]

Scala Functions

Scala Closures

Scala Closures with Examples | See What is Behind the Magic

1. Scala Closures In this chapter, we find out about closures in Scala. We will learn about the problem that Scala Closures solve, Examples of Closures in Scala, see what is behind the magic and working of Datatypes. 2. The Problem What do you do when you want to pass a function around like a variable? How do you let it refer to one or more fields in the same scope? This piece is to address this issue. 3. Scala […]


Scala Arrays and Multidimensional Arrays in Scala

1. Scala Arrays and Multidimensional Arrays Today, we will learn about Scala arrays, how to declare and process them, and multidimensional arrays. We will also see how to create them with Range and concatenating them. So, let’s begin our tutorial on Arrays in Scala. 2. Introduction to Arrays in Scala When we want to hold a number of elements of the same kind in a collection, we use an array. An array is sequential and is of a fixed size. […]

Scala Arrays and Multidimensional Arrays

Scala String Interpolation

Scala String Interpolation | s String, f String and raw string Interpolator

1. Scala String Interpolation Today in Scala String Interpolation tutorial, we will discuss the string interpolators ‘s’, ‘f’, and ‘raw’. But before we begin, let’s find out a little about string interpolation. 2. Introduction to Interpolation in String Interpolation of string is a new way to create them. But we didn’t always have this feature at hand. This was introduced in Scala 2.10, and is available in all newer versions as well. By interpolating a string, we can embed variable […]


Scala String Method with Syntax and Method

1. Scala String Method In this tutorial on Scala String Method, we will discuss the methods defined by the class java.lang.String. Before you proceed with this, you should check out a brief introduction to Strings in Scala. 2. List of String Method in Scala with Example 1. char charAt(int index) This method returns the character at the index we pass to it. Isn’t it so much like Java? scala> “Ayushi”.charAt(1) res2: Char = y 2. int compareTo(Object o) This Scala […]


Scala Data Types with Examples | Escape Value & Typecasting

1. Scala Data Types Hello, readers! Welcome back to learning Scala with DataFlair. Today, we will discuss Scala Data Types with basic literals, Escape value, typecasting and its examples. Hop on. 2. Introduction to Data Types in Scala Like every other language, Scala has a type for every value. We saw this when we discussed variables and values. Even functions have a value. So, let’s understand the Scala data types hierarchy for unified types. Here, the supertype for all types […]


Learn Scala Environment Setup and Get Started with an IDE

1. Scala Environment Setup This article on Scala Environment Setup will guide you through setting up Scala for your system. If you still haven’t begun with the language, now’s your chance. 2. Prerequisites to Setup Scala Environment We know that Scala runs on the JVM. So for Scala Environment Setup, you’ll need to have Java installed on your machine. To check, open the command prompt and type the following: This tells us that we have Java 1.8 involved. If it […]


Introduction to Scala String

Scala String: Creating String, Concatenation, String Length

1. Scala String In this chapter, we will discuss Scala String in Detail. After this, you will be able to create a string, find its length, create a format string, and concatenate strings. We can’t wait to begin. 2. Introduction to Strings in Scala An immutable object, a string in Scala is a sequence of characters. Once we declare it, we cannot modify it. The following is a string: “Ayushi” 3. Creating a Scala String To define a Scala string, […]