Wednesday 27 September 2017

8)Pattern Matching in Scala

Pattern Matching in Scala:
Pattern matching is a mechanism for checking a value against a pattern.  and much similar to java switch statement.

Syntax:
A match expression with the match keyword and at least one case clause.
varible_name match
{
case value => rep_value
.....
}

Simple Example:



Note:
Wild card _ - which means it will match anything.

Pattern matching to store the result in varible:

let's we try to hold the return match result into variable.

Example:




Pattern matching with or condtion:
passing or (|) filter in the case conditon

Example:











1 comment:

Fundamentals of Python programming

Fundamentals of Python programming: Following below are the fundamental constructs of Python programming: Python Data types Python...