AppDividend
Latest Code Tutorials

Java String toUpperCase() Example Tutorial

0

Java String toUpperCase() Example Tutorial is today’s topic. Suppose you want to convert any string to all lower characters, then you have to use Java String toUpperCase() method. This method helps us to convert a string into all lowercase characters. The java string toUpperCase() method returns the string in the uppercase letter. In other words, it converts all characters of the string into an upper case letter.

Java String toUpperCase()

The toUpperCase() method has two variants.

The first variant converts all of the characters in this String to upper case using the rules of the given Locale. This is equivalent to calling toUpperCase(Locale.getDefault()).

Variants

This method has two variants they are:

String toUpperCase():

This method gets the current value of the default locale using toUpperCase (Locale.getDefault()) method for the instance of the Java Virtual Machine. This Java Virtual Machine sets default locale during the start of the host environment. However, it can be changed using the setDefault() method.

Syntax: 
public String toUpperCase()

See the following program.

class Upper {
	public static void main(String args[]) {
		// initializing the string
		String s = "Welcome to APPDIVIDEND";
		// converting string s to uppercase letter
		String str = s.toUpperCase();
		System.out.println(str);
	}
}

See the output.

 

Java String toUpperCase()

String toUpperCase(Locale locale)

The method converts a string into UpperCase using the rules defined by some specified Locale.

Syntax: 

public String toUpperCase(Locale loc)

Here loc converts all characters into uppercase value using the rules defined in Locale.

See the following program.

import java.util.Locale;

class Upper {
    public static void main(String args[]) {
        // initializing the string
        String s = "Welcome to appdividenD.";
        // converting string s to uppercase letter using Locale method
        String eng = s.toUpperCase(Locale.ENGLISH);
        System.out.println(eng);
        String turkish = s.toUpperCase(Locale.forLanguageTag("tr")); // It shows i without dot
        System.out.println(turkish);
    }
}

See the output.

 

Java String toUpperCase() Example

toUpperCase(Locale locale) Method

See the following code example.

import java.util.Locale;

public class StringUpper {
    public static void main(String[] args) {
        String s = "Breaking Bad";
        String turkish = s.toUpperCase(Locale.forLanguageTag("tr"));
        String english = s.toUpperCase(Locale.forLanguageTag("en"));
        System.out.println(turkish);// will print I with dot on upper side
        System.out.println(english);
    }
}

See the output.

➜  java javac StringUpper.java
➜  java java StringUpper
BREAKİNG BAD
BREAKING BAD
➜  java

Finally, Java String toUpperCase() Example Tutorial is over.

Recommended Posts

Java Trim String Example

The valueOf() Function In Java

Java String Contains Example

Java String getchars() Method

Concat() In Java Example

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.