Java Array Remove removeFirst(String[] args)

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

Description

Removes first item from a string array

License

Open Source License

Parameter

Parameter Description
args a parameter

Declaration

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

Method Source Code

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

import java.util.*;

public class Main {
    /**//from w  w  w .j  ava2 s  .co m
     * Removes first item from a string array
     *
     * @param args
     * @return
     */
    public static String[] removeFirst(String[] args) {
        List<String> out = fromArray(args);

        if (!out.isEmpty()) {
            out.remove(0);
        }
        return toArray(out);
    }

    /**
     * Converts string array to ArrayList<String>, remove empty strings
     *
     * @param values
     * @return
     */
    public static List<String> fromArray(String... values) {
        List<String> results = new ArrayList<>();
        Collections.addAll(results, values);
        results.remove("");
        return results;
    }

    /**
     * Converts ArrayList<String> to string array
     *
     * @param list
     * @return
     */
    public static String[] toArray(List<String> list) {
        return list.toArray(new String[list.size()]);
    }
}

Related

  1. removeElement(T[] array, int i)
  2. removeElement(T[] array, T removeObject)
  3. removeElementInStringArray(String[] array, int index)
  4. removeEmpties(String[] array)
  5. removeEmtpyStrings(String[] strings)
  6. removeFirst(String[] array)
  7. removeFirst(String[] in)
  8. removeFirst(String[] strArr)
  9. removeFirstElementFromArray(T[] array)