自学内容网 自学内容网

set的特点

package test_27

case class Book(var bookName:String, var author: String, var price: Double){

}
 object caseclass{
   def main(args: Array[String]): Unit = {
     val set1 = scala.collection.mutable.Set[Book]()

     val book1 =new Book("西游记","吴承恩",100)
     val book2 =new Book("西游记","吴承恩",100)
     val book3 =new Book("西游记","吴承恩",100)

     println(book1 ==book2)

     set1 +=book1
     set1 +=book2
     set1 +=book3

     set1.foreach(s =>{
       println(s.author)
     })
   }
 }

结果是:true
              吴承恩


原文地址:https://blog.csdn.net/wjwjssjjs/article/details/143746445

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!