Character 类的 isLowerCase(char ch) 方法确定给定(或指定)字符是否为小写字符。
如果 Character.getTyper(char ch) 给出的一般类别是 LOWERCASE_LETTER 或者它具有一些贡献属性,则该字符被认为是小写字符。
用法
public static boolean isLowerCase(char ch)
参数
ch: 这是需要测试的字符。
返回值
isLowerCase(char ch) 方法返回一个布尔值,即如果给定(或指定)字符为小写,则返回 true。否则,该方法返回 false。
例子1
import java.util.Scanner;
public class JavaChracterisLowerCaseExample1{
public static void main(String[] args) {
// Ask the user for the first input.
System.out.print("Enter the first character:");
// Use the scanner class to get the user input.
Scanner s1 = new Scanner(System.in);
// Gets a single character.
char value1 = s1.nextLine().toCharArray()[0];
// Check whether the user input is in lower case or not.
boolean check1 = Character.isLowerCase(value1);
// Print the first result.
if(check1){
System.out.print("The first character \'"+value1+"\' is in lower case.\n");
}
else{
System.out.print("The first character \'"+value1+"\' is not in lower case.\n");
}
System.out.print("Enter the second character:");
Scanner s2 = new Scanner(System.in);
char value2 = s2.nextLine().toCharArray()[0];
boolean check2 = Character.isLowerCase(value2);
if(check2){
System.out.print("The second character \'"+value2+"\' is in lower case.\n");
}
else{
System.out.print("The second character \'"+value2+"\' is not in lower case.\n");
}
}
}
输出:
Enter the first character:H The first character 'H' is not in lower case. Enter the second character:h The second character 'h' is in lower case.
例子2
public class JavaChracteisLowerCasetExample2{
public static void main(String[] args) {
// Create four char primitives ch1, ch2, ch3 and ch4.
char ch1;
char ch2;
char ch3;
char ch4;
// Assign the values to ch1, ch2, ch3 and ch4.
ch1 = 'A';
ch2 = 'b';
ch3 = 'M';
ch4 = 'k';
// Create four boolean primitives b1, b2, b3 and b4.
boolean b1 = Character.isLowerCase(ch1);
boolean b2 = Character.isLowerCase(ch2);
boolean b3 = Character.isLowerCase(ch3);
boolean b4 = Character.isLowerCase(ch4);
String str1 = "The first character '"+ ch1+ "' is in lower case:" + b1;
String str2 = "The second character '"+ch2+"' is in lower case:" + b2;
String str3 = "The third character '"+ch3+ "' is in lower case:" + b3;
String str4 = "The fourth character '"+ch4+ "' is in lower case:" + b4;
// Print the values of b1, b2, b3 and b4.
System.out.println( str1 );
System.out.println( str2 );
System.out.println( str3 );
System.out.println( str4 );
}
}
输出:
The first character 'A' is in lower case:false The second character 'b' is in lower case:true The third character 'M' is in lower case:false The fourth character 'k' is in lower case:true
例子3
public class JavaChracterisLowerCaseExample3{
public static void main(String[] args) {
// Create three char primitives ch1, ch2 and ch3.
char ch1, ch2, ch3;
// Assign the values to ch1, ch2 and ch3.
ch1 = 'A';
ch2 = 'a';
ch3 = '_';
// Create three boolean primitives b1, b2 and b3.
boolean b1, b2, b3;
// Check whether the characters ch1, ch2 and ch3 are in lowercase or not and assign the results to b1, b2 and b3.
b1 = Character.isLowerCase(ch1);
b2 = Character.isLowerCase(ch2);
b3 = Character.isLowerCase(ch3);
String str1 = "The first character '"+ch1 +"' is in lowercase:" + b1;
String str2 = "The second character '"+ch2 +"' is in lowercase:" + b2;
String str3 = "The third character '"+ch3 +"' is in lowercase:" + b3;
// Print the values of b1, b2 and b3.
System.out.println( str1 );
System.out.println( str2 );
System.out.println( str3 );
}
}
输出:
The first character 'A' is in lowercase:false The second character 'a' is in lowercase:true The third character '_' is in lowercase:false
Java 字符 isLowerCase() 方法
字符类的 isLowerCase(int codePoint) 方法确定给定(或指定)字符是否为小写字符。
如果 Character.getTyper(int codePoint) 给出的一般类别是 LOWERCASE_LETTER 或者它具有一些贡献属性,则该字符被认为是小写字符。
用法
public static boolean isLowerCase(int codePoint)
参数
codePoint:codePoint 是需要测试的字符。
返回值
isLowerCase(int codePoint) 方法返回一个布尔值,即如果给定(或指定)字符是小写的,则返回 true。否则,该方法返回 false。
例子1
public class JavaCharacterIsLowerCaseExample1 {
public static void main(String[] args) {
// Create four char primitives codePoint1, codePoint2, codePoint3 and codePoint4.
int codePoint1;
int codePoint2;
int codePoint3;
int codePoint4;
// Assign the values to codePoint1, codePoint2, codePoint3 and codePoint4.
codePoint1 = 77;
codePoint2 = 116;
codePoint3= 198;
codePoint4 = 102;
// Create four boolean primitives b1, b2, b3 and b4.
boolean b1, b2, b3,b4;
// Check whether the codePoint1, codePoint2, codePoint3 and codePoint4 are letters or digits or not and assign the results to b1, b2, b3 and b4.
b1 = Character.isLowerCase(codePoint1);
b2 = Character.isLowerCase(codePoint2);
b3 = Character.isLowerCase(codePoint3);
b4 = Character.isLowerCase(codePoint4);
String str1 = "The first codePoint '"+codePoint1 + "' is in lowercase:" + b1;
String str2 = "The second codePoint '"+codePoint2 + "' is in lowercase:" + b2;
String str3 = "The third codePoint '"+codePoint3 + "' is in lowercase:" + b3;
String str4 = "The fourth codePoint '"+codePoint4 + "' is in lowercase:" + b4;
// Print the values of str1, str2, str3 and str4.
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
System.out.println(str4);
}
}
输出:
The first codePoint '77' is in lowercase:false The second codePoint '116' is in lowercase:true The third codePoint '198' is in lowercase:false The fourth codePoint '102' is in lowercase:true
例子2
public class JavaCharacterIsLowerCaseExample2 {
public static void main(String[] args) {
// Create two int primitives cp1 and cp2.
int cp1, cp2;
// Assign the values to cp1 and cp2.
cp1 = 0x0045;
cp2 = 0x0f89;
// Create two boolean primitives b1 and b2.
boolean b1, b2;
b1 = Character.isLowerCase(cp1);
b2 = Character.isLowerCase(cp2);
String str1 = "The first character represents as a lowercase character:" + b1;
String str2 = "The second character represents as a lowercase character:" + b2;
// Print the values of b1 and b2.
System.out.println( str1 );
System.out.println( str2 );
}
}
输出:
The first character represents as a lowercase character:false The second character represents as a lowercase character:false
相关用法
- Java Character isLowSurrogate()用法及代码示例
- Java Character isLetter()用法及代码示例
- Java Character isLetterOrDigit()用法及代码示例
- Java Character isAlphabetic()用法及代码示例
- Java Character isValidCodePoint()用法及代码示例
- Java Character isISOControl()用法及代码示例
- Java Character isSpace()用法及代码示例
- Java Character isMirrored()用法及代码示例
- Java Character isBmpCodePoint()用法及代码示例
- Java Character isIdentifierIgnorable()用法及代码示例
- Java Character isDigit()用法及代码示例
- Java Character isJavaIdentifierPart()用法及代码示例
- Java Character isUpperCase()用法及代码示例
- Java Character isJavaLetterOrDigit()用法及代码示例
- Java Character isWhitespace()用法及代码示例
- Java Character isDefined()用法及代码示例
- Java Character isJavaIdentifierstart()用法及代码示例
- Java Character isHighSurrogate()用法及代码示例
- Java Character isSpaceChar()用法及代码示例
- Java Character codePointCount()用法及代码示例
注:本文由纯净天空筛选整理自 Java Character isLowerCase() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。