list string互转

package com.test;

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

public class Test {

	public static void main(String[] args) {
		//list转string
		List<String> lst = new ArrayList<String>();
		lst.add("1");
		lst.add("2");
		String s = lst.toString();
		s = s.substring(1, s.length()-1);
		System.out.println(s);//打印出:1, 2
		
		//string转list
		String[] arr = s.split(",");
		List list = Arrays.asList(arr);  
		System.out.println(list.toString());//打印出:[1,  2]
	}
}

你可能感兴趣的:(java)