Java examples for Collection Framework:Array Convert
Converts a list(separated with a space) to array
public class Main{ /**Converts a list(separated with a space) to array*/ public static String[] parseArray(String line) { String[] retStrings = new String[0]; String nLine = ""; for (int i = 0; i < line.length(); i++) { if (Character.toString(line.charAt(i)).equals(" ")) { retStrings = addToList(nLine, retStrings); nLine = ""; } else { nLine = nLine.concat(Character.toString(line.charAt(i))); }//from ww w .j av a 2 s .c o m } return retStrings; } public static String[] addToList(String object, String[] array) { String[] ret = new String[array.length + 1]; for (int i = 0; i < array.length; i++) { ret[i] = array[i]; } ret[array.length] = object; return ret; } }