【发布时间】:2018-10-18 19:06:09
【问题描述】:
我有一个字符串,例如:“Adam”,我会将一个字符串拆分为一个单字符字符串数组。("a","d","a","m")
你的建议?
【问题讨论】:
我有一个字符串,例如:“Adam”,我会将一个字符串拆分为一个单字符字符串数组。("a","d","a","m")
你的建议?
【问题讨论】:
String string = "Adam";
String[] splitString = string.split(""); // Split string by each char
for (String character : splitString) {
System.out.println(character); // You can initiate object TextView here and add it to separate list
}
来自文档:
公共字符串[] 拆分(字符串正则表达式)
围绕给定正则表达式的匹配拆分此字符串。
这个方法的工作方式就像是通过调用两个参数的 split 方法 给定的表达式和零的极限参数。尾随空 因此字符串不包含在结果数组中。
例如,字符串“boo:and:foo”会产生以下结果 用这些表达方式:
Regex Result : { "boo", "and", "foo" } o { "b", "", ":and:f" }参数: regex - 分隔正则表达式 返回: 通过围绕给定正则表达式的匹配拆分此字符串计算的字符串数组
【讨论】:
String str = "Adam";
TextView[] textViews = new TextView[4];
textViews[0] = textView1;
textViews[1] = textView2;
textViews[2] = textView3;
textViews[3] = textView4;
for(int i=0; i<str.length(); i++) {
textViews[i] = str.charAt(i);
}
【讨论】: