Java Array Trim trimRecords(String[] records)

Here you can find the source of trimRecords(String[] records)

Description

trim Records

License

Open Source License

Declaration

public static String[] trimRecords(String[] records) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Educational Online Test Delivery System
 * Copyright (c) 2013 American Institutes for Research
 * /* w  ww  .j a va 2s .c  o  m*/
 * Distributed under the AIR Open Source License, Version 1.0
 * See accompanying file AIR-License-1_0.txt or at
 * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf
 ******************************************************************************/

import java.util.Arrays;

public class Main {
    public static String[] trimRecords(String[] records) {
        return Arrays.copyOf(trimTextValues(records), records.length, String[].class);
    }

    public static Object[] trimTextValues(Object[] records) {

        Object[] trimmedRecordArray = new Object[records.length];

        for (int i = 0; i < records.length; i++) {
            Object record = records[i];

            if (record instanceof String || record instanceof Number) {
                trimmedRecordArray[i] = record.toString().trim();
            } else {
                trimmedRecordArray[i] = record;
            }
        }

        return trimmedRecordArray;
    }
}

Related

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