OneBite.Dev - Coding blog in a bite size

convert a string to lowercase in java

Code snippet on how to convert a string to lowercase in java

  String strLower = str.toLowerCase();
  System.out.println(strLower);

This code converts a string to lowercase. The first line creates a string object called str with the text “HELLO WORLD” stored in it. The second line calls the toLowerCase() method on the string object and stores the result in a new string object called strLower. Lastly, the third line prints out the value stored in the strLower object to the console. This line is necessary to see the output of the conversion; it would otherwise remain stored internally.

java