原文地址 : http://www.cnblogs.com/azhqiang/p/5587191.html
1.关于java.lang.string.split
xxx.split()方法可以将一个字符串分割为子字符串,然后将结果作为字符串数组返回。
2.字符串转字符数组
String str =" aa.png,a2.png,a3.png";
String[] arrayStr =new String[]{};
arrayStr = str.split(",");
3.字符数组转list
List list = java.util.Arrays.asList(arrayStr);
4.list转化为字符数组
String[] storeStr = list.toArray(new String[list.size()]);
示例:
public class SplitTest {
public static void main(String args[]) {
String str = "a1.png,a2.png,a3.png";// 原始字符串
String[] arrayStr = new String[] {};// 字符数组
List<String> list = new ArrayList<String>();// list
arrayStr = str.split(",");// 字符串转字符数组
list = java.util.Arrays.asList(arrayStr);// 字符数组转list
String[] storeStr = list.toArray(new String[list.size()]);// list转成字符数组
/* 输出字符数组的值 */
for (String s : arrayStr) {
System.out.println(s);
}
System.out.println("-------------");
/* 输出list值 */
for (String s : list) {
System.out.println(s);
}
System.out.println("-------------");
for (String s : storeStr) {
System.out.println(s);
}
System.out.println("-------------");
}
}