Here you can find the source of quoteEach(String string)
public static String quoteEach(String string)
//package com.java2s; //License from project: Open Source License public class Main { public static String quoteEach(String string) { String[] pieces = string.split("(\\s)+"); StringBuffer result = new StringBuffer(); for (String piece : pieces) { if (piece.indexOf("\"") >= 0) { // already quoted return string; }/*w w w .j a v a2 s. c o m*/ if (!piece.isEmpty()) { result.append(" \""); result.append(piece); result.append("\"\n"); } } return result.toString(); } }