package com.hezhikeji.controller;
public class Test {
//首字母转小写
public static String toLowerCaseFirstOne(String s)
{
if(Character.isLowerCase(s.charAt(0)))
return s;
else
return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
}
//首字母转大写
public static String toUpperCaseFirstOne(String s)
{
if(Character.isUpperCase(s.charAt(0)))
return s;
else
return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
}
public static void main(String[] args) {
//输出test
System.out.println(toLowerCaseFirstOne("test"));
//输出test
System.out.println(toLowerCaseFirstOne("Test"));
//输出Test
System.out.println(toUpperCaseFirstOne("test"));
//输出Test
System.out.println(toUpperCaseFirstOne("Test"));
}
}
Java转换字符串首字母大小写
最新推荐文章于 2024-08-16 10:39:11 发布