Home android Convert char to string

Convert char to string

Author

Date

Category

Guys, this is the problem, I hook the first character from a variable like string like this:

char came_buffer;
   String sbprint;
   came_buffer = sbprint.charAt (0);

and then I need to translate this character from char to string , Google does not give a sensible answer, only some self-written functions that do not really work


Answer 1, authority 100%

Well, I, of course, understand that the question is ridiculous, but why minus something like that? Essentially – & gt;

public static String valueOf (char [] data, int start , int length)

Creates a new string containing the specified characters in the character array. Modifying the character array after creating the string has no effect on the string.


Answer 2, authority 17%

char ch = 'S';
// using the Character class
String charToString = Character.toString (ch);
System.out.println (charToString);
// using the add operation of the String class
String str = "" + ch;
System.out.println (str);
// using an array
String fromChar = new String (new char [] {ch});
System.out.println (fromChar);
// using the valueOf method of the String class
String valueOfchar = String.valueOf (ch);
System.out.println (valueOfchar);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions