1.将字符串转换为字符串数组的方法
String string = "a,b,c";
String [] stringArr= string.split(",");
String str="sdfsfsdfsdfsdfsdf";
char[] aa=str.toCharArray();
2.将字符串数组转换回字符串的简单方法
String(aa);//同上例
3.list转换为Array的方法
如下三种方法
1). Long[] l = new Long[<total size>];
list.toArray(l);
2). Long[] l = (Long[]) list.toArray(new Long[0]);
3). Long[] a = new Long[<total size>];
Long[] l = (Long[]) list.toArray(a);
下面这段代码是接口源码
public Object[] toArray() {
Object[] result = new Object[size];
System.arraycopy(elementData, 0, result, 0, size);
return result;
}
4.Array 转List两种方法:
1)String[] userid = {"aa","bb","cc"};
List<String> userList = Arrays.asList(userid);
2)List<String> userList = new ArrayList<String>();
Collections.addAll(userList, userid);
5.String转char数组的方法
String.toCharArray()
6.数组排序的方法
Arrays.sort(a);
7.字符串分隔成数组
例如:
String a = “Hello world”;
String[] A = a.split(" ");//按照空格分
若
a = “ Hello World ”;//前后都有空格
可用
String[] A = a.trim().split(" ");//trim 可以去掉收尾的空格