循环拼接List并以逗号间隔

package list;

import java.util.ArrayList;
import java.util.List;

public class list {
	public static void main(String[] args) {
		
		
		List<String> resultList = new ArrayList<String>();
		resultList.add("a1");
		resultList.add("a2");
		resultList.add("a3");
		resultList.add("a4");
			StringBuffer resultBuffer = new StringBuffer();
			for (int i = 0; i < resultList.size(); i++) {
				String result = resultList.get(i);
				if (i == 0) {
					resultBuffer.append(result);
				} else {
					resultBuffer.append("," + result);
				}
			}
		String	testResult = resultBuffer.toString();
		System.out.println(testResult);
		}

}

猜你喜欢

转载自blog.csdn.net/Mr_ZhangAdd/article/details/84561853