将一维数组存到二维数组 、将一维数组存到列表
public class Test0202 { public static void main(String[] args) throws ParseException { //将一维数组加入到二维数组 //二维数组 String arr[][] = new String[3][]; //一维数组 String name[] = {"zs","ls","ww"}; String nick[] = {"z1","l2","w3"}; String pass[] = {"a123","l123","w123"}; arr[0]=name; arr[1]=nick; arr[2]=pass; //遍历 for(String x1[]:arr) { for(String x:x1) { System.out.print(x+"\t"); } System.out.println(); } } }
结果
zs ls ww
z1 l2 w3
a123 l123 w123
将一维数组存到列表
//一维数组 String name[] = {"zs","ls","ww"}; String nick[] = {"z1","l2","w3"}; String pass[] = {"a123","l123","w123"}; List<String[]> array= new ArrayList<String[]>(); array.add(name); array.add(nick); array.add(pass); for(String x1[]:array) { for(String x:x1) { System.out.print(x+"\t"); } System.out.println(); }
结果:
zs ls ww
z1 l2 w3
a123 l123 w123