Scala's differences about Array,list,tuple

Source: Internet
Author: User

  1. InScala 2.7in whichArray,Listcannot mix types, onlyTupleYes, and in Scala,3 elements can be mixed with different types (into any type), except when using mixed types. The array and list convert the element type to any type, while the tuple retains the initial type of each element ;

  2. About Array,list,tuple

  3. About initializing

    1)   Val array= new Array[string] (3)// array (NULL, NULL, NULL) is equivalent to a null element that declares 3 null values

  4. val array= Array ("A", "B", "C", "D")// equivalent array.apply ("A", "B", "C", "D")

defines a type of any of the Array :

    val AA = Array[any] (1, 2) val aa:array[any] = Array (1, 2) or: val aa:array[_] = Array (1, 2)

    2)   V [ int  = List (1,3,4,5,6)//  v al list = List (1,3,4,5,6)

        (:::) implements the overlay list, (::) Cons: Combines the new elements into the front of the list. The element is merged using::, the collection is merged using:::, an example is as follows: where nil represents an empty element

       val List2 = "A":: "B":: "C":: Nil//nil

    v al list4 = list2:::list3

3)tuples are immutable, but tuples can be different types of data, instantiation: var a = (,), you can access elements by dot, underscore,-N (N 1-based) index


Scala's differences about Array,list,tuple

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.