問題描述
有沒有辦法把一個(gè) char
變成一個(gè) String
或一個(gè)帶有一個(gè)字母的 String
變成一個(gè) char
(例如如何將 int
轉(zhuǎn)換為 double
并將 double
轉(zhuǎn)換為 int
)?(如果可以,請(qǐng)鏈接到相關(guān)文檔).
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
into a double
and a double
into an int
)? (please link to the relevant documentation if you can).
我如何才能找到我在文檔中只是模糊地知道的類似內(nèi)容?
How do I go about finding something like this that I'm only vaguely aware of in the documentation?
推薦答案
char firstLetter = someString.charAt(0);
String oneLetter = String.valueOf(someChar);
您可以通過識(shí)別可能涉及的類來(lái)查找文檔.在這里,候選是 java.lang.String
和 java.lang.Character
.
You find the documentation by identifying the classes likely to be involved. Here, candidates are java.lang.String
and java.lang.Character
.
您應(yīng)該首先熟悉:
java.lang
中的原始包裝器java.util
中的Java Collection框架
- Primitive wrappers in
java.lang
- Java Collection framework in
java.util
它還有助于通過教程更慢地介紹 API.
It also helps to get introduced to the API more slowly through tutorials.
- 處理字符串中的字符
這篇關(guān)于在 Java 中,如何將 String 轉(zhuǎn)換為 char 或?qū)?char 轉(zhuǎn)換為 String?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!