Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how does "toLowerCase" work?

 
nick magic
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it with "KiSS".
 
mohit junejaa
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic