split the string as characters with whitespace in java [duplicate]
开发者_如何学运维Possible Duplicate:
How to insert Space after every Character of an existing String in Java?
If I get string value from user then I want to display as separate characters. for example: Enter the string: Orange Characters in the String: O r a n g e Can you help any one for this?
Try the following
String text = "Orange";
String spaced = text.replaceAll("(.)", "$1 ");
System.out.println(spaced);
prints
O r a n g e
Have you looked at String.toCharArray()
? Or just use the length()
property and charAt()
to get at each character individually.
Hint:
.toCharArray()
String.toCharArray()
then get the letters together with Spaces between.
精彩评论