日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在Scala中设置&()方法

發(fā)布時間:2025/3/11 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在Scala中设置&()方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Scala中的Set&()方法 (The Set &() method in Scala)

The &() method in the Set is used to create a new set in Scala. This new set created contains all elements from the other two sets that are common for both of the given sets i.e. new set created is the intersection of two sets.

集合中的&()方法用于在Scala中創(chuàng)建一個新集合。 創(chuàng)建的這個新集合包含兩個給定集合中共有的其他兩個集合中的所有元素,即,創(chuàng)建的新集合是兩個集合的交集。

Syntax:

句法:

set1.&(set2)

parameter(s):

參數(shù):

  • set2 – It represents the set for the intersection.

    set2 –表示相交的集合。

Return value:

返回值:

It returns a new set that has all elements of both the sets.

它返回一個包含兩個集合的所有元素的新集合。

Let's see a few examples, for the usage of this function,

讓我們看幾個例子,關(guān)于這個函數(shù)的用法,

Case 1: When both sets have common elements.

情況1:兩組都具有相同的元素。

object myObject { def main(args:Array[String]) { val set1 = Set(13, 89, 57, 23, 96)println("Set1 : "+ set1)val set2 = Set(01, 90, 13, 54, 89, 234, 54)println("Set2 : "+ set2)val set3 = set1.&(set2)println("The intersection of two sets : "+ set3)} }

Output

輸出量

Set1 : HashSet(57, 89, 96, 13, 23) Set2 : HashSet(234, 13, 54, 90, 89, 1) The intersection of two sets : HashSet(89, 13)

Case 2: When sets donot have common elements

情況2:集合沒有共同元素時

object myObject { def main(args:Array[String]) { val set1 = Set(13, 89, 57, 23, 96)println("Set1 : "+ set1)val set2 = Set(01, 90, 54, 234, 54)println("Set2 : "+ set2)val set3 = set1.&(set2)println("The intersection of two sets : "+ set3)} }

Output

輸出量

Set1 : HashSet(57, 89, 96, 13, 23) Set2 : Set(1, 90, 54, 234) The intersection of two sets : HashSet()

翻譯自: https://www.includehelp.com/scala/set-and-method.aspx

總結(jié)

以上是生活随笔為你收集整理的在Scala中设置&()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。