0

I was wondering how exactly one would convert a string of non-alphanumeric symbols into a string array. For example, what would be the code that takes the string

"@%$!#& (&$#^"

as an input, and converts it into a string array

{"@", "%", etc}

1 Answers1

0

Create a String array of the length of string..

int size = theString.length();
String[] asStringArray = new String[size];

then step through that array/String adding chars from the String with charAt()

for (int i=0; i<size; i++){
  asStringArray[i] = ""+theString.charAt(i);
}

Other option is substring()

  asStringArray[i] = theString.substring(i,i+1);
Ross Drew
  • 8,163
  • 2
  • 41
  • 53