Java examples for Collection Framework:Array Element
Trims the String content on an array of String.
//package com.java2s; public class Main { public static void main(String[] argv) { String array = "java2s.com"; System.out.println(java.util.Arrays.toString(trimArray(array))); }//from ww w.j av a 2s . co m /** * Trims the String content on an array of String. * * @param array String array to trim contents. */ public static String[] trimArray(final String... array) { String[] retval = null; //NOPMD: null default, conditionally redefine. if (array != null) { retval = new String[array.length]; System.arraycopy(array, 0, retval, 0, array.length); for (int i = 0; i < retval.length; i++) { if (array[i] == null) { retval[i] = array[i]; } else { retval[i] = array[i].trim(); } } } return retval; } }