reesjones reesjones - 1 year ago 67
Java Question

How to convert String to ArrayList<String>

Let's say I have this String -

string = "AEIOU";

and I wanted to convert it to an
, where each character is it's own individual
within the

[A, E, I, O, U]

EDIT: I do NOT want to convert to
(yes, that's very straightforward and I do pay attention in class), but I DO want to convert to an

How would I do that?

mre mre
Answer Source

transform the String into a char array,

char[] cArray = "AEIOU".toCharArray();

and while you iterate over the array, transform each char into a String, and then add it to the list,

List<String> list = new ArrayList<String>(cArray.length);

for(char c : cArray){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download