×

Java String toUpperCase() methods

Java String toUpperCase() method is used to convert all the characters of the String into upper case.

Syntax

public String toUpperCase()
public String toUpperCase(Locale locale)

Returns

It returns upper case String.

Java String toUpperCase() Example 1:

public class JavaStringtoUpperCaseEx1 {
    public static void main(String args[]) {
        String S1 = new String("lowercase converted to uppercase ");
        //Convert to UpperCase
        System.out.println(S1.toUpperCase());
    }
}

Output:

LOWERCASE CONVERTED TO UPPERCASE

Java String toUpperCase() Example 2:

public class JavaStringtoUpperCaseEx2
    { 
        public static void main(String[] args)
        { 
            String str  = " tutorial and example ";
           System.out.println(str.toUpperCase());
            }
  }

Output:

TUTORIAL AND EXAMPLE

Java String toUpperCase() Example 3:

public class JavaStringtoUpperCaseEx3
    { 
        public static void main(String[] args)
        { 
            String str  = "tutorialandexample";
            String str2 = "TUTORIALANDEXAMPLE";          
           System.out.println(str.toUpperCase().equals(str2));
            }
  }

output:

true

Java String toUpperCase(Locale locale) Method Example 4:

import java.util.Locale;
public class JavaStringtoUpperCaseEx4
{
    public static void main(String args[])
    {
        String s = "you love python, but i love java.";
        // Locales with the language "tr" for TURKISH
        //"en" for ENGLISH is created
        Locale TURKISH = Locale.forLanguageTag("tr");
        Locale ENGLISH = Locale.forLanguageTag("en");
        // converting string s to lowercase letter
        // using TURKISH and ENGLISH language
        String S1 = s.toUpperCase(TURKISH);
        String S2 = s.toUpperCase(ENGLISH);
        System.out.println("In turkish language: "+S1);
        System.out.println("In English language: "+S2);
    }
}

Output:

In turkish language: YOU LOVE PYTHON, BUT ? LOVE JAVA.
In English language: YOU LOVE PYTHON, BUT I LOVE JAVA.

Related Topics

Star Program in Java

By solving the patterns, we can develop our coding skills and logical thinking. Mostly each pattern program uses two or more loops. Loops' number depends on the complexity of logic....

3 minutes read.

Difference between C, C++, java

C Language: C language is a procedure oriented language. It has been invented by Dennis Ritchie in the year 1970. It is one of the computer programming language. The purpose of...

3 minutes read.

Median Of Stream Of Running Integers in Java

An integer array is given to us. Compute the median of the elements traversed so far in the input array. For the sake of simplicity, assume that there are no...

10 minutes read.

Bin Packing Problem Java

Assigning some items with known weights to bins with consistent capacities is necessary for the bin packing problem. The goal is to use the smallest possible boxes while ensuring everything is put...

6 minutes read.

Java Break Keyword

Break: The word Break is a keyword or a statement in a java programming language.This Keyword break is used to stop the execution of the loop or switch statements etc.The loop...

3 minutes read.

How to encrypt password in Java

Every software program needs a username and password to identify a legitimate user. A username can be any number of things, including an email address or a string of characters....

6 minutes read.

Java vs JavaScript

Java Vs JavaScript Java and JavaScript, both play an important role in the field of Computer Technology. Most people think JavaScript is a part of Java. But it is not entirely...

4 minutes read.

Two Decimal Places Java

When a double data type is used in Java before a variable, this indicates 15 digits after decimal point. However, there are situations when we only require 2 decimal places...

4 minutes read.

Java String concat() method:

Java String concat() method is used to add the given String to the end of the current String. Syntax: public String concat(String str) Parameter: Str: String to be concatenated at the end of current...

1 minute read.

Java Boolean compareTo() method

The compareTo() method of Java Boolean class compares the Boolean argument with the Boolean instance and returns integer value, zero, or negative 1, or positive 1 based on the result...

2 minutes read.

Java.lang.Exception.NoRunnableMethods

In Programming language, the java lang unexpected no precompiled methods error generally refers to a Junit exception that happens whenever Junit is incapable of locate the precompiled test methods. When...

4 minutes read.

GCD Program in Java

GCD Program in Java The GCD program in Java outputs the GCD of the given numbers. In mathematics, Greatest Common Divisor (GCD), Greatest Common Factor or Highest Common Factor (HCF) of...

14 minutes read.

Java Math sin() Method

The sin() method of Java Math class returns the trigonometric sine of the specified angle. Syntax: public static double sin(double a) Parameters: The parameter ‘a’ represents an angle measured in radians. Return Value: The sin() method...

1 minute read.

Java String endsWith() method

Checks whether this String ends with the specified suffix or not. Syntax public boolean endsWith(String Suffix) Parameter Suffix : It takes suffix as a parameter  i.e. Sequence of characters Returns It returns true when the current...

1 minute read.

Java Math.multiplyExact() method

In java, we are provided with multiplyExact method in the Math module. This Math module belongs to the java.lang package. In general, this method returns the product of the provided...

2 minutes read.

Process and Thread in Java

Process It is a program that is running on your computer. The process is a heavy-weight, which takes memory separately to other processes. The process may be a small background task like spell-checker; it...

11 minutes read.

Java Pop

The array, linked list, stack, queue, and other data structures are supported by Java programming. The insertion, deletion, and element searching operations are available for every data structure. And Java...

4 minutes read.

Java TreeMap

TreeMap in Java with Example Java TreeMap implements the NavigableMap interface. It extends Map Interface. Java TreeMap is based on the red-black Tree implementation. It stores the key-value pair in sorted...

7 minutes read.

Java Static Keyword

It can be either said that static declares the value to be the same, not only in the instance of a class but also as the whole. To declare a variable...

6 minutes read.

Features of Java

The objective of the Java programming language is to provide portability, security, and simplicity. In spite of this, Java has a number of features that makes it a popular language...

5 minutes read.