Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
object HelloWorld {
case class Book(title: String, yearPublished: Integer, author: String, isbn: String)
val progInScala = Book("Programming in Scala 3rd Edition", 2016, "Martin Odersky", "0981531687")
val funcProgInScala = Book("Functional Programming in Scala", 2014, "Paul Chiusano", "1617290653")
val scalaCookbook = Book("Scala Cookbook", 2013, "Alvin Alexander", "1449339611")
val matchCase = progInScala match {
case Book(title, yearPublished, author, isbn) => println(s"$title <=> $yearPublished <=> $author <=> isbn")
case _ => println("Did not match anything!")
}
val authMatch = progInScala match {
case Book(_, yearPublished, _, _) => println(yearPublished)
case _ => "No Author!"
}
def main(args: Array[String]) {
val number = 10
val isMatch = number match {
case 0 => "Zero"
case 5 => "Five"
case 9 => "Nine"
case _ => "No matches!"
}
println(isMatch)
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more