Scala的Array习题
答案:CBBBB
import scala.collection.mutable.ArrayBuffer
//1
case class DreamItem(content:String,var isDone:Boolean,deadline:String,var order:Int)
object p5 {
def main(args: Array[String]): Unit = {
//2
val dreamList=ArrayBuffer[DreamItem]()//梦想清单
//3
val dream1=DreamItem("梦想1",true,"2022-5-10",1)
val dream2=DreamItem("梦想2",false,"2024-9-22",2)
val dream3=DreamItem("梦想3",true,"2023-2-9",3)
dreamList+=dream1
dreamList+=dream2
dreamList+=dream3
dreamList+=DreamItem("梦想4",true,"2022-5-10",1)
dreamList+=DreamItem("梦想5",true,"2022-5-10",1)
dreamList+=DreamItem("梦想6",true,"2022-5-10",1000)
dreamList+=DreamItem("梦想7",true,"2022-5-10",1000)
dreamList+=DreamItem("梦想8",true,"2022-5-10",1000)
dreamList+=DreamItem("梦想9",true,"2022-5-10",1000)
dreamList+=DreamItem("梦想10",true,"2022-5-10",1000)
//4
dreamList(1).isDone = true
//5
dreamList(2).order=100
//6
val list=dreamList.sortWith((a,b)=>a.order > b.order)
val newList=list.slice(0,5)
list.foreach(e=>{
println(s"${e.content} \t\t ${e.isDone} \t ${e.order}")
})
}
}
原文地址:https://blog.csdn.net/2403_87107889/article/details/143887873
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!