beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Java – String toLowerCase() and toUpperCase() Methods

By Chaitanya Singh | Filed Under: String handling

The method toLowerCase() converts the characters of a String into lower case characters. It has two variants:

String toLowerCase(Locale locale): It converts the string into Lowercase using the rules defined by specified Locale.

String toLowerCase(): It is equivalent to toLowerCase(Locale.getDefault()). Locale.getDefault() gets the current value of the default locale for this instance of the Java Virtual Machine. The Java Virtual Machine sets the default locale during startup based on the host environment. It is used by many locale-sensitive methods if no locale is explicitly specified. It can be changed using the setDefault() method.

Example: toLowerCase() method

import java.util.Locale;
public class LowerCaseExample{
   public static void main(String args[]){
       String str = new String("ABC IS NOT EQUAL TO XYZ");
       //Standard method of conversion
       System.out.println(str.toLowerCase());

       //By specifying Locale
       System.out.println(str.toLowerCase(Locale.FRANCE));
   }
}

Output:

abc is not equal to xyz
abc is not equal to xyz

Method: toUpperCase()

Like toLowerCase() method, toUpperCase() also has two variants:
String toUpperCase(Locale locale): It converts the string into a UpperCase string using the rules defined by the specified Locale.
String toUpperCase(): It is equavalent to toUpperCase(Locale.getDefault()).

Example: toUpperCase() method

import java.util.Locale;
public class UpperCaseExample{
   public static void main(String args[]){
       String str = new String("this is a test string");
       //Standard method of conversion
       System.out.println(str.toUpperCase());

       //By specifying Locale
       System.out.println(str.toUpperCase(Locale.CHINA));
   }
}

Output:

THIS IS A TEST STRING
THIS IS A TEST STRING

Enjoyed this post? Try these related posts

  1. Java String replace(), replaceFirst() and replaceAll() method
  2. Java String isEmpty() method with example
  3. Java – String getChars() Method example
  4. Java String equals() and equalsIgnoreCase() Methods example
  5. Java – String copyValueOf() Method example
  6. Java String startsWith() Method with example

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Tutorials

  • Learn Java
  • OOPs Concepts
  • Java Collections

Java String

  • Java String

Java String Methods

  • String charAt()
  • String compareTo()
  • String compareToIgnoreCase()
  • String contains()
  • String concat()
  • substring
  • String valueOf()
  • String startsWith()
  • String equals()
  • String format()
  • String endsWith()
  • String indexOf()
  • String lastIndexOf()
  • String length()
  • String replace()
  • String split()
  • String trim()
  • String intern()
  • String isEmpty()
  • String matches()
  • String regionMatches()
  • String contentEquals()
  • String toCharArray()
  • String getBytes()
  • String join()
  • String getChars()
  • String copyValueOf()

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap