aspose file tools*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how does "toLowerCase" work?" Watch "how does "toLowerCase" work?" New topic
Author

how does "toLowerCase" work?

nick magic
Greenhorn

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
thanks!


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";

to

public String title="KiSs";

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

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
Marshal

Joined: Mar 22, 2005
Posts: 41889
    
  63
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.


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how does "toLowerCase" work?