如何转换/解析从字符串到Java中的字符? [英] How to convert/parse from String to char in java?

查看:103
本文介绍了如何转换/解析从字符串到Java中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Java中的 String 值解析为 char 类型?

How do I parse a String value in Java to a char type?

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

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