开发者

split the string as characters with whitespace in java [duplicate]

This question already has answers here: Closed 11 years ago.
开发者_如何学运维

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜