Java String Ends With endsWithWhitespace(String s)

Here you can find the source of endsWithWhitespace(String s)

Description

ends With Whitespace

License

Open Source License

Declaration

public static boolean endsWithWhitespace(String s) 

Method Source Code

//package com.java2s;
/*//  w w  w. j a  va  2 s.co m
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

public class Main {
    public static boolean endsWithWhitespace(String s) {
        return (s.length() > 0) && Character.isWhitespace(s.charAt(s.length() - 1));
    }

    public static final int length(Object string) {
        if (string instanceof String)
            return ((String) string).length();
        if (string instanceof StringBuffer)
            return ((StringBuffer) string).length();
        throw new IllegalArgumentException("expecting String or StringBuffer");
    }

    public static boolean isWhitespace(String s) {
        if (s == null)
            return false;
        for (int i = s.length() - 1; i >= 0; i--) {
            char c = s.charAt(i);
            if (!Character.isWhitespace(c))
                return false;
        }
        return true;
    }
}

Related

  1. endsWithSpaces(final String text)
  2. endsWithStarsPattern(String text, int from)
  3. endsWithStartOfOther(String text, String textOther)
  4. endsWithStop(String str)
  5. endsWithWhitespace(final CharSequence charSeq)
  6. endsWithWord(StringBuffer strBuf, int endIndex, int lastSpaceIndex)