1. 程式人生 > >string通過逗號分割不用split方法

string通過逗號分割不用split方法

new 不用 ray rgs bst mon java sys port

package com.simon;

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

public class Study {
	public static void main(String[] args) {
		List<String> list = new ArrayList<String>();
		String b = "abc,12,dad,dada";
		int i = b.indexOf(‘,‘);
		while (i >= 0) {
			list.add(b.substring(0,i));
			b=b.substring(i + 1, b.length());
			i = b.indexOf(",");
		}
		list.add(b);
		String[] str = (String[])list.toArray(new String[list.size()]);
		for (String string : str) {
			System.out.print(string+‘\t‘);
		}
	}
}

  

string通過逗號分割不用split方法