+ 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.

5th Apr 2018, 3:59 AM
Ynelle Kyle Novicio
Ynelle Kyle Novicio - avatar
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!
5th Apr 2018, 5:38 AM
Dev
Dev - avatar
+ 3
May this help you, this is an example https://code.sololearn.com/cgL1AQ4k23R7/?ref=app
5th Apr 2018, 5:12 AM
Jorge Sanchez Tamayo
Jorge Sanchez Tamayo - avatar
0
I've seen they used toCharArray(), but is it possible that it will not be used to convert?
5th Apr 2018, 4:00 AM
Ynelle Kyle Novicio
Ynelle Kyle Novicio - avatar