Java Utililty Methods Array Trim

List of utility methods to do Array Trim

Description

The list of methods to do Array Trim are organized into topic(s).

Method

String[]trim(String[] array)
trim
List<String> trimmed = new ArrayList<String>(array.length);
for (String s : array) {
    if (s != null && !"".equals(s)) {
        trimmed.add(s);
return trimmed.toArray(new String[trimmed.size()]);
String[]trim(String[] array)
trim
List<String> trimmed = new ArrayList<String>(array.length);
for (String s : array) {
    if (s != null && !"".equals(s)) {
        trimmed.add(s);
return trimmed.toArray(new String[trimmed.size()]);
String[]trim(String[] data)
trim
List<String> result = new ArrayList<String>();
for (String val : data) {
    String trimmed = val.trim();
    if (!trimmed.isEmpty()) {
        result.add(trimmed);
return result.toArray(new String[] {});
...
String[]trim(String[] s)
Trims all element in given array.
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]);
...
String[]trim(String[] strings)
trim
if (strings == null)
    return null;
String[] result = new String[strings.length];
for (int i = 0; i < strings.length; i++) {
    String s = strings[i];
    result[i] = s.trim();
return result;
...
char[]trimArray(char[] buffer, int read)
trim Array
if (buffer.length != read) {
    return Arrays.copyOf(buffer, read);
} else {
    return buffer;
byte[]trimArray(final byte[] seq, final int trimFromFront, final int trimFromBack)
Trim any number of bases from the front and/or back of an array
if (trimFromFront + trimFromBack > seq.length)
    throw new IllegalArgumentException("trimming total is larger than the original array");
return (trimFromFront == 0 && trimFromBack == 0) ? seq
        : Arrays.copyOfRange(seq, trimFromFront, seq.length - trimFromBack);
byte[]trimBytes(byte[] source, int fromIndex, int toIndex)
trim Bytes
int from = source.length - toIndex;
int to = source.length - fromIndex;
return Arrays.copyOfRange(source, from, to);
byte[]trimLeadingZeros(byte[] original)
trim Leading Zeros
int index = 0;
while (0x0 == original[index])
    ++index;
return java.util.Arrays.copyOfRange(original, index, original.length);
byte[]trimLeft(byte[] src, int trimSize)
Returns a byte array left trimmed of trimSize elements
if (trimSize >= src.length)
    throw new IllegalArgumentException(
            "Unable to trim " + trimSize + " elements from an array of " + src.length + " elements ");
return Arrays.copyOfRange(src, trimSize, src.length);