isMixedCase()
is a static method of the StringUtils
class that is used to check if the given string contains both uppercase and lowercase characters.
false
if the input string is null
.false
if the input string is empty.StringUtils
?StringUtils
is defined in the Apache Commons Lang package. Apache Commons Lang can be added to the Maven project by adding the following dependency to the pom.xml
file.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the commons-lang package, refer to the Maven Repository.
You can import the StringUtils
class as follows:
import org.apache.commons.lang3.StringUtils;
public static boolean isMixedCase(final CharSequence cs)
final CharSequence cs
: the character sequence/string to be checkedThis method returns true
if the string contains both uppercase and lowercase characters. Otherwise, it returns false
.
import org.apache.commons.lang3.StringUtils;public class Main {public static void main(String[] args) {String s = "educATIve";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = "educ ATIve";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = "23asfg";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = "";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = null;System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = " ";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = "\u002f\u0045";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = "educative";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();s = "EDUCATIVE";System.out.printf("The output of StringUtils.isMixedCase() for the string - '%s' is %s", s, StringUtils.isMixedCase(s));System.out.println();}}
string - "educATIve"
The method returns true
because the string contains both uppercase and lowercase characters.
string - "educ ATIve"
The method returns true
because the string contains both uppercase and lowercase characters.
string - "23asfg"
The method returns false
because the string only contains lowercase characters and numbers.
string - ""
The method returns false
because the string is empty.
string - null
The method returns false
because the string points to null
reference.
string - " "
The method returns false
because the string contains only spaces that are neither uppercase nor lowercase characters.
string - "\u002f\u0045"
The method returns false
because the string contains Unicode letters which are neither uppercase nor lowercase characters.
string - "educative"
The method returns false
because the string contains lowercase characters only.
string - "EDUCATIVE"
The method returns false
because the string contains uppercase characters only.
The output of the code will be as follows:
The output of StringUtils.isMixedCase() for the string - 'educATIve' is true
The output of StringUtils.isMixedCase() for the string - 'educ ATIve' is true
The output of StringUtils.isMixedCase() for the string - '23asfg' is false
The output of StringUtils.isMixedCase() for the string - '' is false
The output of StringUtils.isMixedCase() for the string - 'null' is false
The output of StringUtils.isMixedCase() for the string - ' ' is false
The output of StringUtils.isMixedCase() for the string - '/E' is false
The output of StringUtils.isMixedCase() for the string - 'educative' is false
The output of StringUtils.isMixedCase() for the string - 'EDUCATIVE' is false