Changing the Case of a String - Java Language Basics

Java examples for Language Basics:String

Introduction

Use the toUpperCase() and toLowerCase() methods.

Demo Code

import java.util.Locale;

public class Main {
    public static void main(String[] args){

        String str = "This String will change case.";
        //from w  w w.  j  av a  2  s  . c om
        System.out.println(str.toUpperCase());
        System.out.println(str.toLowerCase());
        System.out.println(str.toUpperCase(Locale.ITALIAN));
        System.out.println(str.toUpperCase(new Locale("it","US")));
        System.out.println(str.toLowerCase(new Locale("fr", "CA")));
    }
    
 }

Result


Related Tutorials