Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java string split

Tags:

java

What should I do if I want to split the characters of any string considering gaps and no gaps?

For example, if I have the string My Names James I want each character individually like this: M y n a m e s etc.

like image 503
N. F. Avatar asked Jun 13 '26 08:06

N. F.


1 Answers

You mean this?

   String sentence = "Hello World";
   String[] words = sentence.split(" ");

Also if you would like to get the chars of the string you could do this:

char[] characters = sentence.toCharArray();

Now you just need a loop to iterate the characters and do whatever you want with them.

Here a link to the java API documentation there you can find information about the String class.

http://download.oracle.com/javase/6/docs/api/

I hope this was useful to you.

like image 97
javing Avatar answered Jun 15 '26 22:06

javing