Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toLowerCase(char) method?

Tags:

java

character

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.

like image 283
oadams Avatar asked Mar 27 '11 06:03

oadams


People also ask

Does toLowerCase work on char?

The toLowerCase() method is a static method in the Character class in Java, which is used to convert a character to lowercase. The input to this function is a character. If you need to convert a string to lowercase, refer to the String. toLowerCase method.

How do I use character toLowerCase in Java?

toLowerCase(char ch) converts the character argument to lowercase using case mapping information from the UnicodeData file. Note that Character. isLowerCase(Character. toLowerCase(ch)) does not always return true for some ranges of characters, particularly those that are symbols or ideographs.

Is toLowerCase () a string method in Java?

Java String toLowerCase() method is used and operated over string where we want to convert all letters to lowercase in a string. There are two types of toLowerCase() method as follows: toLowerCase() toLowerCase(Locale loc): Converts all the characters into lowercase using the rules of the given Locale.

How do you use toLowerCase function?

The toLowerCase method converts a string to lowercase letters. The toLowerCase() method doesn't take in any parameters. Strings in JavaScript are immutable. The toLowerCase() method converts the string specified into a new one that consists of only lowercase letters and returns that value.


2 Answers

toLowerCase is a static method, as such you need to qualify it with the class it belongs to, as

Character.toLowerCase(c);
like image 64
MeBigFatGuy Avatar answered Oct 04 '22 10:10

MeBigFatGuy


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);  
    }  
}  
like image 24
Abhi Avatar answered Oct 04 '22 10:10

Abhi