In Java how does one turn a String into a char or a char into a String?

前端 未结 7 1561
感情败类
感情败类 2020-12-08 01:55

Is there a way to turn a char into a String or a String with one letter into a char (like how you can turn an int

7条回答
  •  佛祖请我去吃肉
    2020-12-08 02:11

    As no one has mentioned, another way to create a String out of a single char:

    String s = Character.toString('X');
    

    Returns a String object representing the specified char. The result is a string of length 1 consisting solely of the specified char.

提交回复
热议问题