Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a String into an array of Strings containing one character each

I have a small problem here.I need to convert a string read from console into each character of string. For example string: "aabbab" I want to this string into array of string.How would I do that?

like image 663
gingergeek Avatar asked Sep 03 '09 10:09

gingergeek


People also ask

Can you turn a string into an array?

Using toArray() Method We can also convert String to String array by using the toArray() method of the List class. It takes a list of type String as the input and converts each entity into a string array.

Which method can be used to convert all characters in a string into a character array?

char[] toCharArray() : This method converts string to character array. The char array size is same as the length of the string. char charAt(int index) : This method returns character at specific index of string.


1 Answers

String[] result = input.split("(?!^)");

What this does is split the input String on all empty Strings that are not preceded by the beginning of the String.

like image 74
Joachim Sauer Avatar answered Oct 05 '22 08:10

Joachim Sauer