Extractor is getting values from an expression
The match code in the 27th lecture is also an extractor
def match_array (arr:any) = arr Match {case Array (x) + println ("Array (1):", x)//array of length 1, x represents the value in the array case arr Ay (x, y) = println ("Array (2):", x, y)//An array of length 2, x represents the first value in the array case Array (x,_*) = println ("Any one-dimensional array:", X)//arbitrary-length array, fetch The first value case Array (_*) = = println ("Any one-dimensional array")///arbitrary-length array} match_array (Array (0)) Match_array (Array ("Spark" )) Match_array (Array ("Spark", "Scala")) Match_array ("Spark", "Scala", 0,4))
Extracts elements from an array to constants defined in the case, such as X, Y
There is also an extractor that extracts data using regular expressions
Val pattern = "([0-9]+) ([a-z]+)". R "Spark" match {case pattern (num,item) = println (num+ "" +item)}
This article is from the "Ding Dong" blog, please be sure to keep this source http://lqding.blog.51cto.com/9123978/1741929
28th Lecture: Scala Extractor Extractor actual combat