在Java中如何将String转换为char或char转换为String? [英] In Java how does one turn a String into a char or a char into a String?

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

问题描述

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

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