Home Java Convert a String to Uppercase in Java

Convert a String to Uppercase in Java

In this example we show you how to convert a string to uppercase in Java

Example

We will take input from the user

We will then use the built-in function toUpperCase() on the given string and display the result.

import java.util.Scanner;

public class JavaApplication1 
{
    private static Scanner myScanner;
    public static void main(String[] args) 
    {
    String myString;
	myScanner= new Scanner(System.in);

	System.out.print("\nPlease Enter String =  ");
	myString = myScanner.nextLine();
	
	String upString = myString.toUpperCase();	
	System.out.println("\nThe Uppercase String  =  " + upString);
    }
}

Here is a test run

Please Enter String = my test striNG

The Uppercase String = MY TEST STRING

You may also like