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.
Simple Example:
Note:
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:
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:
Good Blog,Thanks for sharing this information.
ReplyDeleteSpark Scala Online Training