package controller;

import java.util.ArrayList;

public class Mytest {

/**
* 将集合变为集合中的数据变成字符串输出,并以','好分隔,且最后一个没有逗号
* @param args
*/
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
/* String[] array=new String[list.size()];
list.toArray(array);
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]);
}*/
StringBuffer buffer=new StringBuffer();
for (String str : list) {
buffer.append(str +",");
}
String substring = buffer.substring(0,buffer.length()-1);
System.out.println(substring.toString());
//以‘,’分隔拆分再输出
String[] split = substring.toString().split(",");
for (int i = 0; i < split.length; i++) {
String string = split[i];
System.out.println(string);
}

test.test2();
}


/**
* 将集合转换为数组输出
* @author Administrator
*
*/
static class test{
public static void test2(){
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
String[] list=new String[arrayList.size()];
arrayList.toArray(list);
for (int i = 0; i < list.length; i++) {
String string = list[i];
System.out.print(string);
}
}
}
}