1. 程式人生 > >Java 帶逗號的字串轉換成List

Java 帶逗號的字串轉換成List

字串轉成String型別的List

String str ="123,234,45,365,456";
方法1:List<String> result = Arrays.asList(str.split(","));
String str ="avc,safa,ghgf,fd";
方法2:List<String> result = Splitter.on(",").trimResults().splitToList(str); 
方法3:List<String> str = Arrays.asList(StringUtils.commaDelimitedListToStringArray(str));
方法4:List<String> result = Arrays.asList(StringUtils.split(str,","));

字串轉成Integer型別的List

	String str ="123,234,456,567,786";
	String[] arrStr = str.split(",");
	List<Integer> intList = new ArrayList<Integer>(); 
	for(int i=0;i<arrStr.length;i++){
		intList.add(Integer.valueOf(arrStr[i]).intValue());
	}
以上僅供參考!!!