Scala Learning six: special characters in Scala

Source: Internet
Author: User
Tags foreach
Scala Learning six: special characters in Scala special characters in Scala instructions for use:
Object Scalaoperator {def main (args:array[string]) {///::: Three colons: 2 collections merged println ("-------[:::]") Val list1 = List (1, 2) Val list2 = List (3, 4) Val listcombine = List1::: List2 Listcombin
        E.foreach (x = {println (x)}) println ("-------[::]")//:: 2 colon elements added to the collection element in front, set in after Val d = 5:: listcombine//= = Method Body indicator D.foreach (x = {println
        (x)})//-Construct a tuple of $ two println ("-------[->]") val one = 1 val dual = 2 Val C = one, println (c)///_n used to access data elements in tuples, coordinates starting from 1 println ("-------[_n]") pr Intln ("one =" + c._1) println ("one =" + c._1) println ("-------[<-]")//<-assigns the elements in the collection to Temporary variable for (v <-listcombine) {println ("v =" + V)} println ("-------arrBuf1 [Res
     ULT1] ")//   Val arrBuf1 = new Arraybuffer[int] () arrbuf1.+= (11)//Add an element arrbuf1.+= (33, 44)//Add multiple elements Arrbu F1.insert (1, 22)//in index=1, position insertion arrBuf1 + = 55//Add an element Arrbuf1.append (66)//Recover an element arrbuf1.pre Pend (77)//Append an element to the head arrbuf1.prepend (88)//Append an element to the head arrbuf1.prepend (99)//Append an element to the head for (elem <-arrBuf1) {println (Elem)} println ("-------arrBuf1 [Result2]") Arrbuf1.remove ( 3, 2)//start with index=3, delete 2 elements for (Elem <-arrBuf1) {println (Elem)} println ("------ 
        -ArrBuf1 [RESULT3] ") arrbuf1.trimend (2)//delete tail 2 elements for (Elem <-arrBuf1) {println (elem)
        } val arrBuf3 = arrbuf1.+:(3)//Add an element to the header and return a new collection println ("-------arrBuf3 [result] =")  Arrbuf3.foreach (x = {println (x)}) println ("-------arrBuf2 [result]")//Val
ARRBUF3 = 5 + + arrBuf2        Val arrBuf2 = new Arraybuffer[int] () arrbuf2.+= (3) arrbuf2.+= (4) arrbuf2.foreach (x =

        {println (x)})  println ("-------arrbufcom [result]")//ARRBUF2,ARRBUF1 All elements are added to the new collection arrbufcom, return arrbufcom Val arrbufcom = arrbuf1.++:(arrBuf2) arrbufcom.foreach (x = = {println (x)}) println ("-------ar
            RBUF1 [RESULT4] ")//Add all elements in ArrBuf2 to ARRBUF1 header arrbuf1.++=:(arrBuf2) Arrbuf1.foreach (x = { 
        println (x)})//: _* treats the set element as a sequence of arguments, println ("-------seq:_* [result]") in a function with a variable-length argument list
        Val seq = seq (1, 2, 3, 4, 5) println (my_sum (seq: _*))} def my_sum (args:int*): Int = { var result = 0 for (a <-args) {result + = a} return result}}

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.