Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法将类型的 String 变量转换为"X"字符?
"X"
String state = "X"; char c_state = convertToChar(state);
我该怎么做呢 ?
你可以这样做:
char c_state = state.charAt(0);
您还可以将其转换为 char 数组,如下所示,如果 String 包含超过 1 个字符,这可能非常有用。
char[] charArray = state.toCharArray();
这是另一种方法
char c_state = state.toCharArray()[0];