/** * This function returns all the words present in String parameter passed to it in String array. * If null is passed the default word separator used in function is white space. * * <p> * * @param text {@link java.lang.String} The text from which words would get separated. * @param wordSeperator {@link java.lang.String} The word seperator that is used to separate words * in text from which words would get separated. * @return Array of {@link java.lang.String}[] containing all words separated by white space from * the text. */ public static String[] getWordsSeperated(String text, String wordSeperator) { synchronized (text) { if (isNotEmpty(text)) { text = text.trim().replaceAll("[\\.]|[!]|[\\?]|[,]", " "); String[] words = null; if (null != wordSeperator) { words = text.split(wordSeperator); } else { words = text.split("[\\s]"); } List<String> result = new ArrayList<String>(); for (String word : words) { if (isNotEmpty(word)) { result.add(word); } } return CollectionUtil.toArray(result, String.class); } return new String[] {text}; } }
public static Number median(Collection<? extends Number> col) { Number[] n = CollectionUtil.toArray(col, Number.class); Arrays.sort(n); return n[n.length / 2]; }