Java Array Trim trim(String[] s)

Here you can find the source of trim(String[] s)

Description

Trims all element in given array.

License

Apache License

Parameter

Parameter Description
s an array of original string.

Declaration

public static String[] trim(String[] s) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  www .  ja v a  2  s. co  m*/
     * Trims all element in given array.
     * 
     * @param s
     *            an array of original string.
     * @return
     */
    public static String[] trim(String[] s) {
        if (s == null) {
            return null;
        }
        List<String> list = new ArrayList<String>();
        for (String v : s) {
            list.add(v == null ? null : v.trim());
        }
        return list.toArray(new String[0]);
    }
}

Related

  1. trim(String s, char delimit[])
  2. trim(String[] args)
  3. trim(String[] array)
  4. trim(String[] array)
  5. trim(String[] data)
  6. trim(String[] strings)
  7. trimArray(char[] buffer, int read)
  8. trimArray(final byte[] seq, final int trimFromFront, final int trimFromBack)
  9. trimBytes(byte[] source, int fromIndex, int toIndex)