This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how does Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how does "toLowerCase" work?" Watch "how does "toLowerCase" work?" New topic

how does "toLowerCase" work?

nick magic

Joined: Mar 03, 2006
Posts: 11
public class Book
public String title="kiss";
public String getTitle(){
return title;
public static void main(String[] args)
Book b=new Book();
String s=b.getTitle();
String t=s.toLowerCase();
System.out.println("the title is"+t);
the code prints the title is kiss.
i wonder what does toLowerCase mean

la qualite de la vie!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Try it with "KiSS".

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
mohit junejaa
Ranch Hand

Joined: Feb 24, 2006
Posts: 41
if the string object on which toLowerCase() is invoked contains uppercase characters , then a new string object with all characters lowercase is returned

however if the string does not contain lowercase characters then original string object is returned

scjp 1.4
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
It converts all entire string into lowecase string.
Try to changing the following line:
public String title="kiss";


public String title="KiSs";

and run the program then you will know the difference.
Pran Pal

Joined: Mar 02, 2006
Posts: 10
Next time, type this in google: "java api toLowerCase()". It's going to give you the link to sun's api, which contains all the methods with the description.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The javadocs only tell you what the method does, they rarely talk about how something happens. But the method is written in Java, and part of the class library source (which ships with the JDK), so you can look it up there.

And if you're really interested in how toLowerCase works, check out Peter Norvigs take on it, and study his faster method.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

It's interesting that Norvig picked toLowerCase rather than toUpperCase; his sped-up version cannot be used for toUpperCase because the upper-case version of the ß character is "SS", making the resulting string longer than the source string.
I agree. Here's the link:
subject: how does "toLowerCase" work?
It's not a secret anymore!