char c = 'a';
String s = Character.toString(c);
//s == "a"
// getting single character from string..
String str="abcd";
char c=str.toChar(0);
System.out.println("output is "+c); // output is a
std::string str = "string";
const char *cstr = str.c_str();
char c = 'a';
String s = String.valueOf(c); // fastest + memory efficient
String s = Character.toString(c);
String s = new String(new char[]{c});
String s = String.valueOf(new char[]{c});
String s = new Character(c).toString();
String s = "" + c; // slowest + memory inefficient
String string = "ABCDEF" ;
char[] charsFromString = string.toCharArray(); // { 'A', 'B', 'C', 'D', 'E', 'F' }
std::string str = "string";
const char *cstr = str.c_str();
char c = 'a';
String s = Character.toString(c);
String s = "a";
char c = s.charAt("0");
string.toCharArray();
string temp = "cat";
char * tab2 = new char [temp.length()+1];
strcpy (tab2, temp.c_str());
char c=s.charAt(0);//returns h.
Character.toString('c');
char mChar = 'l';
String s = Character.toString(mChar);
// CPP program for the above approach
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
// Driver Code
int main()
{
char* char_arr;
string str_obj("GeeksForGeeks");
char_arr = &str_obj[0];
cout << char_arr;
return 0;
}
char c;
char *pChar = &c;