Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

java - java中的字符串到字符串数组转换(string to string array conversion in java)

I have a string="name";

(我有一个string="name";)

I want to convert into a string array.

(我想转换成字符串数组。)

How do I do it?

(我该怎么做?)

Is there any java built in function?

(有没有内置的java函数?)

Manually I can do it but I'm searching for a java built in function.

(手动我可以做到,但我正在寻找一个内置的java函数。)

I want an array where each character of the string will be a string.

(我想要一个数组,其中字符串的每个字符都是一个字符串。)

like char 'n' will be now string "n" stored in an array.

(像char'n'现在将字符串“n”存储在一个数组中。)

  ask by riyana translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To start you off on your assignment, String.split splits strings on a regular expression, this expression may be an empty string:

(为了让你的作业开始, String.split在正则表达式上拆分字符串,这个表达式可能是一个空字符串:)

String[] ary = "abc".split("");

Yields the array:

(产生数组:)

(java.lang.String[]) [, a, b, c]

Getting rid of the empty 1st entry is left as an exercise for the reader :-)

(摆脱空的第一个条目留给读者练习:-))

Note: In Java 8, the empty first element is no longer included.

(注意:在Java 8中,不再包含空的第一个元素。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...