如何将字符串转换为每个包含一个字符的字符串数组 [英] How to convert a String into an array of Strings containing one character each

查看:19
本文介绍了如何将字符串转换为每个包含一个字符的字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有一个小问题.我需要将从控制台读取的字符串转换为字符串的每个字符.例如字符串:aabbab"我想将此字符串转换为字符串数组.我该怎么做?

I have a small problem here.I need to convert a string read from console into each character of string. For example string: "aabbab" I want to this string into array of string.How would I do that?

推荐答案

String[] result = input.split("(?!^)");

这样做是在所有空字符串上分割输入字符串,这些空字符串前面没有字符串的开头.

What this does is split the input String on all empty Strings that are not preceded by the beginning of the String.

这篇关于如何将字符串转换为每个包含一个字符的字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆