【问题标题】:What type to use to store a single char in Scala?在 Scala 中使用什么类型来存储单个字符?
【发布时间】:2010-09-19 00:07:48
【问题描述】:

我正在编写一个函数,该函数旨在将一个字符作为参数并返回一个字符。为此使用 String 对我来说有点奇怪。我应该,还是在 Scala 2.8 中有类似 char 类型的东西?

【问题讨论】:

    标签: scala types char


    【解决方案1】:
    Java    Scala
    ----    -----
    boolean Boolean
    byte    Byte
    char    Char
    int     Int
    long    Long
    float   Float
    double  Double
    
    String  String
    

    我感觉到一种模式......

    【讨论】:

      【解决方案2】:

      是的,scala 中有一个字符类型。它叫做Char

      Scala 也有字符文字,就像在大多数语言中一样,它是通过用单引号将字符括起来来编写的。

      【讨论】:

        【解决方案3】:

        如果您只需要基本多语言平面字符,请使用Char。否则,您需要使用Int。有关此问题的讨论,请参阅 the JavaDoc for the Character classthis technical article

        【讨论】:

          猜你喜欢
          • 2015-01-27
          • 2011-04-08
          • 1970-01-01
          • 1970-01-01
          • 2017-11-16
          • 1970-01-01
          • 2011-08-20
          • 2015-02-10
          • 1970-01-01
          相关资源
          最近更新 更多