問題描述
有沒有辦法把一個 char
變成一個 String
或一個帶有一個字母的 String
變成一個 char
(例如如何將 int
轉換為 double
并將 double
轉換為 int
)?(如果可以,請鏈接到相關文檔).
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).
我如何才能找到我在文檔中只是模糊地知道的類似內容?
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);
您可以通過識別可能涉及的類來查找文檔.在這里,候選是 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
.
您應該首先熟悉:
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.
- 處理字符串中的字符
這篇關于在 Java 中,如何將 String 轉換為 char 或將 char 轉換為 String?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!