Scala的集合复习

集合(可变 不可变):Set,List(链表:空间上不连续),Array(数组:空间上连续),Map

序列Sep:表示有先后顺序的集合

集Set:表示无序且不重复的集合

映射Map:表示键值

复制代码
package test3
import scala.collection.mutable


object test3_1 {
  //队列
  // def main(args: Array[String]): Unit = {
//      val q1 = mutable.Queue(1)
//      q1 = enqueue(2)
//      q1 = enqueue(3)
//      q1 = enqueue(4)
//  println(q1.enqueue())//出队 1
//  println(q1.enqueue())//出队 2

  //栈:先进后出
  def main(args: Array[String]): Unit = {
    val s1 = mutable.Stack(1)
    s1.push(2)
    s1.push(3)
    s1.push(4)

    //出栈
    println(s1.pop())// 4
    println(s1.pop())// 3
    println(s1.pop())// 2
  }
}

(二)Scala中的字符串

复制代码
package test4

object test4_1 {
  def main(args: Array[String]): Unit = {
    //字符串
    val id = "622823200402032009"

    //1.取出单个字符
    println(id(0))
    //2.取出他的生日,子串
    //    subString(起点下标,终点下标,不包含)
    val birthday = id.substring(6, 14)
    println(birthday)

    //3.判断性别
    //取出第17位
    val genderCode = id.substring(16, 17).toInt
    //奇数为男,偶数为女
    if(genderCode % 2 == 0) {
      println(s"它的性别是女")
    }else{
      println(s"它的性别是男")
    }
    //  4.前两位表示省份

    //5.最后一位是校验码

    //分割
    val str = "高圆圆,林青霞,章泽天,张曼玉"
    val arr = str.split(",")
    println(arr)
    arr.foreach(e=>{
      println(s"我喜欢${e}")
    })
    //我喜欢高圆圆
    //我喜欢林青霞
    //我喜欢章泽天
  }
}
相关推荐
GoGeekBaird13 分钟前
我开源了 BeeWeave,给 AI Agent 搭一个越用越懂你的知识创作台
后端·github
西门吹-禅2 小时前
java springboot N+1问题
java·开发语言·spring boot
skywalk81632 小时前
设计并实现段言的 C FFI 绑定机制 @Trae
c语言·开发语言·python·编程
犀利豆3 小时前
AI in Harness(四)
人工智能·后端
Hui Baby4 小时前
Spring Security
java·后端·spring
IT笔记4 小时前
【Rust】Rust Match 模式匹配详解
java·开发语言·rust
2zcode4 小时前
免费开源项目文档:基于MATLAB卷积神经网络的口罩佩戴检测系统
开发语言·matlab·cnn
逝水无殇4 小时前
C# 运算符重载详解
开发语言·后端·c#
苏三说技术5 小时前
2026编程圈很火的10个Skills
后端
TPBoreas5 小时前
配置信息防泄露方案:.env 环境隔离详解(dotenv-java)
java·开发语言