Reputation: 3087
Apparently there is a method that takes a char and returns a char: http://download.oracle.com/javase/6/docs/api/java/lang/Character.html#toLowerCase(char)
But I can't seem to get it to work. My code:
import java.lang.Character;
public class Test {
public static void main(String[] args) {
char c = 'A';
c = toLowerCase(c);
System.out.println(c);
}
}
When I compile this, I get the following error:
$ javac Test.java
Test.java:6: cannot find symbol
symbol : method toLowerCase(char)
location: class Test
c = toLowerCase(c);
^
1 error
What am I doing wrong? Thanks.
Upvotes: 14
Views: 54524
Reputation: 429
toLowerCase()
is a static method of Character class. So, you will have to use the class name to invoke the method and pass the character which you want to convert to lower case.
Usage--> Character.toLowerCase(<character to be converted to lowercase>)
Other static methods are-->
toUpperCase
isLowerCase
isUpperCase
isDigit
isAlphabetic
Upvotes: 2
Reputation: 5834
Use your own implementation to convert character to lower case:
c = (char) (c ^ 0x20);
In your method:
public static void main(String[] args) {
char c = 'A';
c = (char) (c ^ 0x20);
System.out.println(c);
}
Upvotes: 0
Reputation: 151
"Character" class is used to perform operations on characters of string i.e. to convert character into uppercase, to lower case etc.These methods are "static", So they do not need objects to call them.can be called by class name.
Example: toLowerCase() method of Character class Character.toLowerCase(char ch) converts the character ch argument to lowercase.
Corrected program is as below:
import java.lang.Character;
public class Test {
public static void main(String[] args) {
char c = 'A';
c = Character.toLowerCase(c);
System.out.println(c);
}
}
Just add the Character before the method toLowerCase() method,because the method is static and should be called by class name.
For more Details Refer following link: http://www.tutorialspoint.com/java/lang/character_tolowercase.htm
Upvotes: 0
Reputation: 1
Just add this statement in a header:
import static java.lang.Character.toLowerCase;
Upvotes: 0
Reputation: 2785
import java.lang.Character;
public class Test {
public static void main(String[] args) {
char c = 'A';
char lc = Character.toLowerCase(c);
System.out.println(lc);
}
}
Upvotes: 4
Reputation: 38482
toLowerCase()
is a method of java.lang.String; you use it like so:
jcomeau@intrepid:/tmp$ cat test.java; java test
public class test {
public static void main(String[] args) {
System.out.println("C".toLowerCase());
}
}
c
Upvotes: 0
Reputation: 28588
toLowerCase is a static method, as such you need to qualify it with the class it belongs to, as
Character.toLowerCase(c);
Upvotes: 32