如何把一段逗号分割的字符串转换成一个数组?

方式一:

        String orgStr="ycc,cheng,chiahi,hello,james";
		String[] str=orgStr.split(",");
		for (String string : str) {
			System.out.println(string);
		}

方式二:

        String orgStr="ycc,cheng,chiahi,hello,kobe";
		StringTokenizer tokener = new StringTokenizer(orgStr,",");
		String [] result = new String[tokener.countTokens()];
		int i=0;
		while(tokener.hasMoreTokens())
		{
			result[i++]=tokener.nextToken();
		}
		
		for (String string : result) {
			System.out.println(string);
		}

你可能感兴趣的:(学习笔记)