Java String with all upper case characters
/*/*from www.j a va2 s. co m*/ Copyright 2009 Semantic Discovery, Inc. (www.semanticdiscovery.com) This file is part of the Semantic Discovery Toolkit. The Semantic Discovery Toolkit is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The Semantic Discovery Toolkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with The Semantic Discovery Toolkit. If not, see <http://www.gnu.org/licenses/>. */ //package com.demo2s; public class Main { public static void main(String[] argv) throws Exception { String s = ""; System.out.println(allCaps(s)); } public static final boolean allCaps(String s) { return allCaps(s, 0, s.length()); } /** * @return true if all letters in the string are upper case and there is at least one letter. */ public static final boolean allCaps(String s, int startPos, int endPos) { boolean allCaps = true; boolean foundOne = false; for (int i = startPos; i < endPos; ++i) { final int c = s.codePointAt(i); if (c > 65535) ++i; if (Character.isLetter(c)) { foundOne = true; if (!Character.isUpperCase(c)) { allCaps = false; break; } } } return allCaps && foundOne; } }
//package com.demo2s; public class Main { public static void main(String[] argv) throws Exception { String str = ""; System.out.println(allCaps(str)); }/*from w w w. j a v a 2 s . c o m*/ /** * Returns true if all characters in the String are upper case. * * @param str * the String to check * @return true, if all characters are upper case. Else false. */ public static boolean allCaps(String str) { int charCount = str.length(); for (int i = 0; (i < charCount); i++) { char ch = str.charAt(i); if (!Character.isUpperCase(ch)) { return false; } } return true; } }