1、字符串——>字符数组:
public class Zhuanhuan { public static void main(String []ags){ String string="fgdshfgdf"; char []c=string.toCharArray(); for(char c1:c){ System.out.println(c1); } } }
public class Zhuanhuan { public static void main(String []ags){ /* String string="fgdshfgdf"; char []c=string.toCharArray(); for(char c1:c){ System.out.println(c1); }*/ char []c={'s','d','f','g'}; StringBuffer string=new StringBuffer(); for(char c1:c){ string.append(c1); } System.out.println(string); } }
ArrayList<String> list=new ArrayList<String>(); list.add("fsdfdf"); list.add("jfklgf"); StringBuffer stringBuffer=new StringBuffer(); for(String s:list){ stringBuffer.append(s); } System.out.println(stringBuffer);
ArrayList<String> list=new ArrayList<String>(); list.add("fsdfdf"); list.add("jfklgf"); String []strings=new String[list.size()]; strings=list.toArray(strings); for(String s:strings) System.out.println(s);
Integer []a={1,5,3,6,2,6,9}; List<Integer> list= Arrays.asList(a); Arrays.sort(a); Collections.sort(list); for(int i:a){ System.out.println(i); } System.out.println(); for(int i:list){ System.out.println(i); }
6、直接输出数组:
Arrays.toString(arr);
7、数组变为List:
List list=Array.asList(arr);