Here you can find the source of mergeArgs(String[] args)
public static String[] mergeArgs(String[] args)
//package com.java2s; import java.util.ArrayList; public class Main { public static String[] mergeArgs(String[] args) { ArrayList<String> merged = new ArrayList<>(); boolean open = false; StringBuilder builder = new StringBuilder(); for (String arg : args) { if (open) { if (builder.length() != 0) { builder.append(' '); }// w w w.j a v a2 s. c o m if (arg.endsWith("\"")) { open = false; builder.append(arg.substring(0, arg.length() - 1)); merged.add(builder.toString()); builder = new StringBuilder(); } else { builder.append(arg); } } else if (arg.startsWith("\"")) { open = true; builder.append(arg.substring(1)); } else { merged.add(arg); } } if (builder.length() != 0) { merged.add(builder.toString()); } return merged.toArray(new String[merged.size()]); } }