trim from string End - Android java.lang

Android examples for java.lang:String Strip

Description

trim from string End

Demo Code

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Random;

public class Main{

    public static String trimEnd(String str) {
        char[] value = str.toCharArray();
        int start = 0, last = value.length - 1;
        int end = last;

        while (end >= start) {
            if (value[end] >= ' ')
                break;
            end--;//from   www. ja v  a  2  s . c om
        }

        return new String(value, start, end - start + 1);
    }

}

Related Tutorials