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

ListgetTrimmedValues(final String[] values)
get Trimmed Values
final List<String> trimmedValues = new ArrayList<>();
for (final String value : values) {
    trimmedValues.add(value.trim());
return trimmedValues;
long[]rtrim(long[] array)
rtrim
int notZeroLen = array.length;
for (int i = array.length - 1; i >= 0; --i, notZeroLen--) {
    if (array[i] != 0) {
        break;
if (notZeroLen != array.length) {
    array = Arrays.copyOf(array, notZeroLen);
...
byte[]safeTrim(byte[] ba, int len)
safe Trim
if (ba == null)
    return null;
if (len == ba.length)
    return ba;
else
    return Arrays.copyOf(ba, len);
char[]safeTrim(final char[] ca, final int len)
safe Trim
if (len == ca.length) {
    return ca;
} else {
    return Arrays.copyOf(ca, len);
byte[]trim(byte[] bytes)
Remove trailing 0 from byte[]
int i = bytes.length - 1;
while (i >= 0 && bytes[i] == 0) {
    --i;
return Arrays.copyOf(bytes, i + 1);
byte[]trim(byte[] bytes, int endMargin)
trim
int i = bytes.length - 1;
while (i >= 0 && bytes[i] == 0) {
    --i;
return Arrays.copyOf(bytes, i + 1 + endMargin);
byte[]trim(byte[] data)
Trim the byte array by removing the leading 0's.
int idx = 0;
while (idx < data.length) {
    if (data[idx] != 0) {
        break;
    idx++;
byte[] trimmedData;
...
byte[]trim(byte[] src, byte padding, boolean right, int minLength)
trim
if (src.length < minLength) {
    throw new RuntimeException("src array is smaller than minLength: " + src.length + " < " + minLength);
if (right) {
    int offset;
    for (offset = src.length - 1; offset > minLength - 1; offset--) { 
        if (padding != src[offset]) {
            break;
...
Stringtrim(String s, char delimit[])
trim
if (s == null) {
    return null;
int length = s.length();
int beginIndex = 0;
int endIndex = length;
for (; beginIndex < length; beginIndex++) {
    char c = s.charAt(beginIndex);
...
String[]trim(String[] args)
trim
return (String[]) Arrays.copyOfRange(args, 1, args.length);