Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 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 Reply

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中,不再包含空的第一个元素。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...