Java Array Merge mergeArgs(String[] args)

Here you can find the source of mergeArgs(String[] args)

Description

merge Args

License

Open Source License

Declaration

public static String[] mergeArgs(String[] args) 

Method Source Code


//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()]);
    }
}

Related

  1. merge(T[] left, T... right)
  2. merge(T[]... arrays)
  3. merge(T[]... many)
  4. merge2TablesWithoutDup(String[] t1, String[] t2)
  5. mergeAndOrderArray(int[] arrA, int[] arrB)
  6. mergeArray(byte[] arr1, byte[] arr2)
  7. mergeArray(final Object[] dest, final Object[]... arrays)
  8. mergeArray(String[] a, String[] b)
  9. mergeArray(T[] objs, String concatenator)