posted 22 years ago
Well, the answer depends on whether you're dealing with an ArrayList or an array, two very different things.
If you're dealing with an array, they don't have any "add" methods -- they very have few methods at all, just the ones inherited from Object (equals, hashCode, etc.) You use "array1[j] = st.charAt(1)" to set an element.
If you're dealing with an ArrayList, you're trying to pass a char to a method add(int, Object), but a char is not an Object. You'd have to convert the char to a String or other object -- precisely what you should do depends on what you're after, exactly.
Now, two other things: first, you ought never to use a "do... while" loop when a "for" loop would work just as well; the "for" loop will be much clearer. Unfortunately, I can't quite figure out the details of this loop's exit condition, so I won't try to translate it for you.
Finally, note that String has a toCharArray() method which returns the String as an array of characters; this method may be useful to you.
[ February 11, 2004: Message edited by: Ernest Friedman-Hill ]