upperCase() is a StringUtils that converts a string to uppercase. This method optionally takes a locale. If the locale is unspecified, the default locale of the system is taken. The method returns null if the input string is null.
StringUtilsThe definition of StringUtils can be found in the Apache Commons Lang package, which we can add 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 String upperCase(final String str, final Locale locale)
final String str: The string to be converted into uppercase.final Locale locale: The locale that defines the case transformation rules.This method returns an uppercased string.
public static String upperCase(final String str)
import org.apache.commons.lang3.StringUtils;import java.util.Locale;public class Main {public static void main(String[] args) {String s = "hellO-EDUcative";System.out.printf("The output of StringUtils.upperCase() for the string - '%s' is %s", s, StringUtils.upperCase(s, Locale.ENGLISH));System.out.println();s = "";System.out.printf("The output of StringUtils.upperCase() for the string - '%s' is %s", s, StringUtils.upperCase(s, Locale.ENGLISH));System.out.println();s = null;System.out.printf("The output of StringUtils.upperCase() for the string - '%s' is %s", s, StringUtils.upperCase(s, Locale.ENGLISH));System.out.println();}}
string = "hellO-EDUcative"locale = englishThe method returns HELLO-EDUCATIVE, where the string is converted to uppercase.
string = ""locale = englishThe method returns `` as the input string is empty.
string = nulllocale = englishThe method returns null as the input string is null.
The output of the code is:
The output of StringUtils.upperCase() for the string - 'hellO-EDUcative' is HELLO-EDUCATIVE
The output of StringUtils.upperCase() for the string - '' is
The output of StringUtils.upperCase() for the string - 'null' is null
Free Resources