Scala Arrays and lists

Source: Internet
Author: User

Scala Arrays and lists:

Import Scala.collection.mutable.ArrayBufferimport scala.collection.mutable.Bufferobject arraylearning {def main (  Args:array[string]): Unit = {//usezipunzip//listops//arrayops//arraybufferops} private def Usezipunzip = {//zip and unzip Val nums = List (1, 2, 3, 4) Val chars = List (' A ', ' B ', ' C ', ' d ') val combinlist = Nums.zi P (chars) println (combinlist) println (Combinlist.unzip)} private def arraybufferops = {//create variable array val Strarra    Yvar = arraybuffer[string] ()//add element at the tail Strarrayvar + = "AAA" println (strarrayvar) Strarrayvar + = ("BBB", "CCC") println (Strarrayvar)//Append any set Strarrayvar ++= List ("ddd", "Eee") println (Strarrayvar)//delete trailing 3 elements Strarra Yvar.trimend (3) println (Strarrayvar)//mutable and immutable variable group conversion val arr:array[string] = Strarrayvar.toarray val arrbuffer: Buffer[string] = arr.tobuffer} private def arrayops = {//create fixed-length array val numberarray = new Array[int] (Ten) Val Stri Ngarray = new Array[string] (10)    Array Assignment Stringarray (0) = "Hello" println (stringarray (0))//Create an array using the array apply method val Strarray = Array ("AAA", "    BBB ")} private Def listops = {val XSS = list (list (triple), List (" A "," B "," C ")) val Flist:list[any] = Xss.flatten println (flist) println (List.concat (List (a), List (4,5,6)) println (list (All)::: List (4,5,6)::: Nil)}}

Scala Arrays and lists

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.