String[] (String[] args) { List<String> cleaned = new ArrayList<>(); StringBuilder currentArg = null; for (String arg : args) { boolean addedToBuffer = false; if (arg.startsWith("\"")) { if (currentArg != null) { cleaned.add(currentArg.toString()); } currentArg = new StringBuilder(arg.substring(1)); addedToBuffer = true; } if (addedToBuffer && arg.endsWith("\"")) { currentArg.setLength(currentArg.length() - 1); cleaned.add(currentArg.toString()); currentArg = null; continue; } if (!addedToBuffer) { if (currentArg != null) { currentArg.append(' ').append(arg); } else { cleaned.add(arg); } } } if (currentArg != null) { cleaned.add(currentArg.toString()); } int cleanedSz = cleaned.size(); String[] cleanArgs; if (cleanedSz == 0) { cleanArgs = args; } else { cleanArgs = ArrayUtil.toStringArray(cleaned); } return cleanArgs; }