Here you can find the source of splitStringOnWhitespace(String text)
Parameter | Description |
---|---|
text | The source String |
public static List splitStringOnWhitespace(String text)
//package com.java2s; import java.util.List; import java.util.ArrayList; public class Main { /** Split the given String on whitespace characters. //w w w . ja v a 2 s .c o m @param text The source String @return A List of String objects */ public static List splitStringOnWhitespace(String text) { List elements = new ArrayList(); StringBuffer buffer = new StringBuffer(); char[] chars = text.toCharArray(); for (int i = 0; i < chars.length; i++) { if (Character.isWhitespace(chars[i])) { if (buffer.length() > 0) { elements.add(buffer.toString()); buffer = new StringBuffer(); } } else { buffer.append(chars[i]); } } if (buffer.length() > 0) { elements.add(buffer.toString()); } return elements; } }