string -> array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

string -> array

how do I take an inputed string and turn it into an array of characters? also, how come my code prints "null" for each character that loops? thank you :) https://code.sololearn.com/cm8Zd68FhTbW/?ref=app

27th Mar 2019, 11:38 PM
koala 🐨
koala 🐨 - avatar
6 Answers
+ 4
String to Array: //use toCharArray() method char[] name = theName.toCharArray(); for(char n: name){ System.out.println(n); }
28th Mar 2019, 12:04 AM
Denise Roßberg
Denise Roßberg - avatar
+ 5
char not Char and inside your loop char not String
28th Mar 2019, 12:10 AM
Denise Roßberg
Denise Roßberg - avatar
+ 4
Why null? String[] name = new String[theName.length()]; This initialize an String array. But it is not filled with values at this time. So you get null in your loop.
28th Mar 2019, 12:09 AM
Denise Roßberg
Denise Roßberg - avatar
+ 4
Your welcome :)
28th Mar 2019, 12:12 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
thank you so much :)
28th Mar 2019, 12:11 AM
koala 🐨
koala 🐨 - avatar
+ 1
I get the error: "cannot find symbol"
28th Mar 2019, 12:09 AM
koala 🐨
koala 🐨 - avatar