In Java how does one turn a String into a char or a char into a String?

Solution 1:

char firstLetter = someString.charAt(0);
String oneLetter = String.valueOf(someChar);

You find the documentation by identifying the classes likely to be involved. Here, candidates are java.lang.String and java.lang.Character.

You should start by familiarizing yourself with:

  • Primitive wrappers in java.lang
  • Java Collection framework in java.util

It also helps to get introduced to the API more slowly through tutorials.

  • Manipulating characters in a String

Solution 2:

String.valueOf('X') will create you a String "X"

"X".charAt(0) will give you the character 'X'