Java 仅根据大小写比较两个不同的字符

Java 仅根据大小写比较两个不同的字符,java,Java,我只想比较两个单独的字符的大小写。例如,“a”==“b”将返回true。其中as'A'=='A'为假。最好的方法是什么?检查Java API中的字符() 你可以用 Character.isUpperCase( x ) == Character.isUpperCase( y ). 对于小写字母,我不太确定如何实现它。我会再打给你的。应用这个 boolean func(char x,char y){ if(Character.isUpperCase(x)==Character.isUpperCas

我只想比较两个单独的字符的大小写。例如,“a”==“b”将返回true。其中as'A'=='A'为假。最好的方法是什么?

检查Java API中的
字符(

你可以用

Character.isUpperCase( x ) == Character.isUpperCase( y ).
对于小写字母,我不太确定如何实现它。我会再打给你的。

应用这个

boolean func(char x,char y){
if(Character.isUpperCase(x)==Character.isUpperCase(y))
return true;
if(Character.isLowerCase(x)==Character.isLowerCase(y))
return true;
else return false;
}

我不明白这里的问题。Java字符比较默认行为区分大小写。所以你所需要的已经通过“==”实现了。您还需要什么?与(假设静态导入)
boolean func(char x,char y){return(isUpperCase(x)&&isUpperCase(y))| |(isLowerCase(x)&&isLowerCase(y));
//Checks Uppercase
if variable.isUpperCase(str.charAt(index)) && variable.isUpperCase(str.charAt(index))
{
    //set variable true
}
boolean func(char x,char y){
if(Character.isUpperCase(x)==Character.isUpperCase(y))
return true;
if(Character.isLowerCase(x)==Character.isLowerCase(y))
return true;
else return false;
}