当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java String toLowerCase()用法及代码示例


Java字符串toLowerCase()方法将字符串的所有字符转换为小写字母。 toLowerCase()方法有两种类型。

签名:

public String toLowerCase(Locale loc) 
and
public String toLowerCase() 
参数:
loc- locale value to be applied. converts all the characters into 
lowercase using the rules of given Locale.  
返回: returns string in lowercase letter.
// Java program to demonstrate 
// working of toLowerCase() method 
  
class Gfg { 
    public static void main(String args[]) 
    { 
        String s = "Welcome! to Geeksforgeeks Planet."; 
  
        // converting string s to lowercase letter 
        String gfg1 = s.toLowerCase(); 
        System.out.println(gfg1); 
    } 
}

输出:


welcome! to geeksforgeeks planet.
// Java program to demonstrate 
// working of Locale class in 
// toLowerCase() method 
import java.util.Locale; 
class Gfg { 
    public static void main(String args[]) 
    { 
        String s = "I Know YOI Bui You Don't Know ME."; 
  
        // Locales with the language "tr" for TURKISH 
        //"en" for ENGLISH is created 
        Locale TURKISH = Locale.forLanguageTag("tr"); 
        Locale ENGLISH = Locale.forLanguageTag("en"); 
  
        // converting string s to lowercase letter 
        // using TURKISH and ENGLISH language 
        String gfg2 = s.toLowerCase(TURKISH); 
        String gfg3 = s.toLowerCase(ENGLISH); 
        System.out.println(gfg2); 
        System.out.println(gfg3); 
    } 
}

输出:

? know yo? bui you don't know me.
i know yoi bui you don't know me.


相关用法


注:本文由纯净天空筛选整理自Niraj_Pandey大神的英文原创作品 Java String toLowerCase() with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。