如何在 Java 中将 String 值解析为 char 类型?
How do I parse a String value to a char type, in Java?
我知道如何对 int 和 double 进行处理(例如 Integer.parseInt("123")).有字符串和字符的类吗?
I know how to do it to int and double (for example Integer.parseInt("123")).
Is there a class for Strings and Chars?
如果您的字符串只包含一个字符,最简单的将其转换为字符的方法可能是调用 charAt 方法:
If your string contains exactly one character the simplest way to convert it to a character is probably to call the charAt method:
char c = s.charAt(0);
这篇关于java - 如何在java中将String转换/解析为char?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
“Char 不能被取消引用"错误quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch 语句 - 是“或"/“和"可能的?Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java替换字符串特定位置的字符?Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
具有 int 和 char 操作数的三元表达式的类型是什么What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
读取文本文件并存储出现的每个字符Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
为什么我需要在 byte 和 short 上显式转换 char 原语Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)