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

前端 未结 7 1519
感情败类
感情败类 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:31
    char firstLetter = someString.charAt(0);
    String oneLetter = String.valueOf(someChar);
    

    You find the documentation by identifying the classes likely to be involved. Here, candidates are java.lang.String and java.lang.Character.

    You should start by familiarizing yourself with:

    • Primitive wrappers in java.lang
    • Java Collection framework in java.util

    It also helps to get introduced to the API more slowly through tutorials.

    • Manipulating characters in a String
    0 讨论(0)
提交回复
热议问题