40th: Set, Map, TreeSet, treemap operation code Combat

Source: Internet
Author: User

code example:

Package com.dt.scala.datasetobject set_map {  def main (args: Array[String]) : unit = {    // set  the collection, the data in the collection is non-repeatable. But the data is unordered.     val dataset = set (1,2,5,4,1,3,2)     println (dataSet )         val dataset2 = dataset.+ (1)  //add elements to the collection, Generate another collection     val dataset3 = dataset.++ (DataSet2)  //  Two collection merge, return new collection         import scala.collection.mutable    //   Define variable collection     val data = mutable. set.empty[int]    data += 1 //adding elements to the collection          data ++=list (3,4)  //  add elements from the list to the collection          println (data)     //  ordered set treeset   &Nbsp;import scala.collection.immutable    val ts = immutable. TreeSet (1,3,2,5,2,3,9,7)     println (TS)  //treeset (1, 2, 3, 5, 7,  9)         //variable treeset    val mts =  mutable. Treeset[int] ()     mts.add (1)     //add a list to TreeSet      mts.++= (List (1,2,3,9,7,5))     println (MTS)              //TreeMap  mapping, sorting values by default     val tmap =  Immutable. TreeMap ("Spark"->10, "Hadoop"->5, "Yarn"->8)         println ( TMap)       }}


This article is from the "Ding Dong" blog, please be sure to keep this source http://lqding.blog.51cto.com/9123978/1742099

40th: Set, Map, TreeSet, treemap operation code 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.