+ 1
Is there a way to convert string to char without using the method supported by java packages?
I'm trying to convert string to char using java language and want to do it without using its provided method or functions for it.
3 Answers
+ 9
You have to use atleast one function, like the charAt(int i) to get the character at a specified index. Check this code,
String myStr = "SoloLearn";
int len = myStr.length();
char[] ch = new char[len];
for(int i=0; i<len; i++) {
ch[i] = myStr.charAt(i);
}
Now the char array has the word SoloLearn!
+ 3
May this help you, this is an example
https://code.sololearn.com/cgL1AQ4k23R7/?ref=app
0
I've seen they used toCharArray(), but is it possible that it will not be used to convert?