Home » Java » In java, can i use string split to split by character?-Exceptionshub

In java, can i use string split to split by character?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

For instance, I have the String variable abbaabbbba. I would like to use String split so each character would be separated, so it would be {a,b,b,a,a,b,b,b,b,a}. All the instructions I can find for string split say i need to have something, like a a space:

String mySplit = str.split("/");

Is there anyway to do this by character?

How to&Answers:

You can use the toCharArray method like this:

String myString = "abbaabbbba";
char[] myCharacters = myString.toCharArray();