Java String Last Index Of lastIndexOfNonWhitespace(final String src)

Here you can find the source of lastIndexOfNonWhitespace(final String src)

Description

last Index Of Non Whitespace

License

Open Source License

Declaration

public static int lastIndexOfNonWhitespace(final String src) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int lastIndexOfNonWhitespace(final String src) {
        return lastIndexOfNonWhitespace(src, src.length(), 0);
    }//from w  ww . ja v  a2 s . c o  m

    public static int lastIndexOfNonWhitespace(final String src, final int startIndex) {
        return lastIndexOfNonWhitespace(src, startIndex, 0);
    }

    public static int lastIndexOfNonWhitespace(final String src, int startIndex, int endIndex) {
        final int total = src.length() - 1;
        if (total < 0) {
            return -1;
        }
        if (startIndex >= total) {
            startIndex = total;
        }
        if (endIndex < 0) {
            endIndex = 0;
        }
        for (int i = startIndex; i >= endIndex; --i) {
            if (!Character.isWhitespace(src.charAt(i))) {
                return i;
            }
        }
        return -1;
    }
}

Related

  1. lastIndexOfIgnoreCase(String str, String searchStr)
  2. lastIndexOfIgnoreCase(String str, String searchStr, int startPos)
  3. lastIndexOfImpl(final String str, final String search, final int fromIndex, final boolean ignoreCase)
  4. lastIndexOfLetter(String string)
  5. lastIndexOfNewline(CharSequence theChars, int aStart)
  6. lastIndexOfOrdinal(String value, String part, int startIndex, int count, boolean caseSensitive)
  7. lastIndexOfPathSeparator(String str)
  8. lastIndexOfSeparator(String path)
  9. lastIndexOfUCL(String value)