Tuesday 19 February 2019

Scala List

Lets work on Scala List


Create a List

Method 1:

scala> val itemList = List(3,6,9)

Method 2:

scala> val itemList = List.range(1,6)
x: List[Int] = List(1, 2, 3, 4, 5)































Monday 18 February 2019

Hello World

Lets try our first Scala Program

Object name: MyFirstProgram.scala

In scala , Object is a singleton class. Meaning, Only one object is created for that class.

Method 1:

object MyFirstProgram{
   def main()={
      println("Hellow world!!!")
   }
}


Method 2:

object MyFirstProgram extends App{
   println("Hellow world!!!")
}

Similar to java MAIN method, in scala APP is the entry point to the program.


How to run this?

First Compile the code

> scalac MyFirstProgram.scala


Next Execute the code

> scala MyFirstProgram