28th Lecture: Scala Extractor Extractor actual combat

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.