Okay im reading in lines of text e.g "abcdefg" and I need to split the line into an array of characters where each character is stored in its own element so its like [a][c][d][e][f][g]

I know how to do it with splitting words from poems etc... using something like txtLine.split(" ") but i dont know how to do it with thse characters. They have no spaces between them?

9 Years
Discussion Span
Last Post by ~s.o.s~

This was also mentioned by myself and s.o.s. two days ago in your other post about the char array... :P


One of the important things you should know as a Java developer is to find the classes in the standard library which contain the functionality you desire. As an example, since you need to operate on Strings and need to generate a char array, looking into the documentation of String and Character classes should be your first step. If that fails, try looking into the java.util package for utility methods which operate on your data. If you need help with text processing and formatting, java.text package should be good to go. This is a pretty good exercise and will actually make you aware of the functionality provided by the Java standard library.

If that fails, use your favorite search engine to give you a solution to your problem. In your case, searching for 'convert string to char array' hit the spot right on.

When everything fails, use discussion groups as your last resort. It's not too much work, really, and if you feel it is, then think that it for your own good. :-)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.