自己实现一个类似trim()方法

public static String myTrim(String str)
{
    int start = 0,end = str.length() - 1;
    while (start <= end && str.charAt(start) ==' ')
    {
        start++;
    }
    while(start <= end && str.charAt(end) ==' ')
    {
        end--;
    } 
    return str.substring(start,end+1);
}

你可能感兴趣的:(自己实现一个类似trim()方法)