Java String Split splitArgs(String args, int expectedArgs)

Here you can find the source of splitArgs(String args, int expectedArgs)

Description

split Args

License

LGPL

Declaration

public static String[] splitArgs(String args, int expectedArgs) 

Method Source Code


//package com.java2s;
/*/*from   ww  w  . jav  a2 s  . c  o m*/
 * This class was created by <AdrianTodt>. It's distributed as
 * part of the DavidBot. Get the Source Code in github:
 * https://github.com/adriantodt/David
 *
 * DavidBot is Open Source and distributed under the
 * GNU Lesser General Public License v2.1:
 * https://github.com/adriantodt/David/blob/master/LICENSE
 *
 * File Created @ [01/11/16 13:23]
 */

import java.util.*;

public class Main {
    public static String[] splitArgs(String args, int expectedArgs) {
        String[] raw = args.split("\\s+", expectedArgs);
        if (expectedArgs < 1)
            return raw;
        return normalizeArray(raw, expectedArgs);
    }

    public static String[] normalizeArray(String[] raw, int expectedSize) {
        String[] normalized = new String[expectedSize];

        Arrays.fill(normalized, "");
        for (int i = 0; i < normalized.length; i++) {
            if (i < raw.length && raw[i] != null && !raw[i].isEmpty()) {
                normalized[i] = raw[i];
            }
        }
        return normalized;
    }
}

Related

  1. split_fields(String str)
  2. split_str(String input, String split)
  3. splitAndTrim(String str)
  4. splitAndTrim(String str, String splitBy)
  5. splitAndUnEscape(String str)
  6. splitArguments(final String str)
  7. splitArguments(String arguments)
  8. splitArguments(String s)
  9. splitArguments(String str)