Java Array Trim trimStringArray(final String[] input)

Here you can find the source of trimStringArray(final String[] input)

Description

Trims an array of Strings to remove the whitespace.

License

Open Source License

Parameter

Parameter Description
input The array of strings to be trimmed

Return

The same array of strings but all elements have been trimmed of whitespace

Declaration

public static String[] trimStringArray(final String[] input) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    /**//  ww w  .  j a va2s . com
     * Trims an array of Strings to remove the whitespace. If the string is empty then its removed from the array.
     *
     * @param input The array of strings to be trimmed
     * @return The same array of strings but all elements have been trimmed of whitespace
     */
    public static String[] trimStringArray(final String[] input) {
        final ArrayList<String> output = new ArrayList<String>();
        for (int i = 0; i < input.length; i++) {
            String s = input[i].trim();
            if (!s.equals(""))
                output.add(s);
        }
        return output.toArray(new String[0]);
    }
}

Related

  1. trimArray(final byte[] seq, final int trimFromFront, final int trimFromBack)
  2. trimBytes(byte[] source, int fromIndex, int toIndex)
  3. trimLeadingZeros(byte[] original)
  4. trimLeft(byte[] src, int trimSize)
  5. trimRecords(String[] records)
  6. trimZeroTail(final double[] data)