trim All String element in an array - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

trim All String element in an array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String[] array = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        System.out.println(java.util.Arrays.toString(trimAll(array)));
    }//from  www  . ja  v a  2  s.  com

    public static String[] trimAll(String[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i].trim();
        }
        return array;
    }
}

Related Tutorials