How to Convert a String to UpperCase in Java? | Java String toUpperCase() Method with Example

In this tutorial, we are going to learn How to Convert a String to UpperCase in Java. In our previous tutorials, we have also discussed how to convert a string to lowercase in java. If you need to learn that please keep in touch with our java tutorials. Here, We will be discussing all the two variants to convert all the characters of a java string to uppercase. First, we have to understand & have knowledge of the basic Java String tutorial.

How to Convert a String to UpperCase in Java?

In Java, we can convert all the characters of a string to UpperCase by using the toUpperCase() method of the Java String class. Like, the toLowerCase() method is used for converting a string to lowercase in java. Here, we will explain all the two variants of the toUpperCase() method.

Java String toUpperCase() Method

This is the initial variant of the toUpperCase() method of the String class. This type of toUpperCase() converts all the characters of a string to UpperCase. This method is equivalent to toUpperCase(Locale.getDefault).

Syntax:

The syntax of the first variant of the toUpperCase() method is given below:

public String toUpperCase()

Java program to convert a string to UpperCase

class toUpperCase{
public static void main(String args[]){
String str = "String Tutorial BY BtechGeeks";
//converting all the characters of
//a string into uppercase.
System.out.println(str.toUpperCase());
}
}

Output:

STRING TUTORIAL BY BTECHGEEKS

Also Check:

2. String toUpperCase(Locale locale) Method in Java

This is the second variant of the Java String toUpperCase() method. This method converts all the characters of a string to UpperCase with the help of the rule of a given locale.

Syntax:

The syntax of the second variant of the toUpperCase() method is given below:

public String toUpperCase(Locale locale)

Java String toUpperCase(Locale locale) Method Example

import java.util.Locale;
class toUpperCase{
public static void main(String args[]){
String str = "String Tutorial BY JavaStudyPoint";

//Locales with the language "tr"
//for turkish and "en" for english.
Locale turkish = Locale.forLanguageTag("tr");
Locale english = Locale.forLanguageTag("en");

//converting string str into lowercase
//using turkish and english language.
String str1 = str.toUpperCase(turkish);
String str2 = str.toUpperCase(english);
System.out.println(str1);
System.out.println(str2);
}
}

Output:

How to Convert a String to UpperCase in Java

Leave a Comment