java - 如何在java中将String转换/解析为char? [英] How to convert/parse from String to char in java?

查看:12
本文介绍了java - 如何在java中将String转换/解析为char?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆