Java Array Remove RemoveArgs(String[] args, int startIndex)

Here you can find the source of RemoveArgs(String[] args, int startIndex)

Description

Remove Args

License

Open Source License

Declaration

public static String RemoveArgs(String[] args, int startIndex) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String RemoveArgs(String[] args, int startIndex) {
        List<String> list = removeFirstTwoArgs(args, startIndex);
        String convertedString = convertToString(list);
        return convertedString;
    }//w w w  .  ja v  a2  s .  c  o  m

    private static List<String> removeFirstTwoArgs(String[] args, int startIndex) {
        List<String> convertedString = new ArrayList<>();
        for (int i = startIndex; i < args.length; i++)
            convertedString.add(args[i]);
        return convertedString;
    }

    public static String convertToString(String[] args) {
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < args.length; i++)
            stringList.add(args[i]);
        return convertToString(stringList);
    }

    private static String convertToString(List<String> strings) {
        StringBuilder builder = new StringBuilder();
        for (String s : strings)
            builder.append(s + " ");
        String out = removeLast(builder.toString());
        return out;
    }

    private static String removeLast(String str) {
        if (str.length() > 0) {
            str = str.substring(0, str.length() - 1);
        }
        return str;
    }
}

Related

  1. remove(String[] target, String[] needRemoved)
  2. remove(T[] a, int i)
  3. removeAll(E[] array, Object... toRemove)
  4. removeAll(T[] array, Collection toRemove)
  5. removeAll(T[] items, T item)
  6. removeAt(T[] array, int index)
  7. removeByPrefix(String[] array, String prefix)
  8. removeByteOrderMark(final byte[] input)
  9. removeCommonWords(String[] words)