java 获取下一个字母(传大写返回大写,传小写返回小写)

时间:2022-12-04 14:56:46
public static String getNextUpEn(String en){  
        char lastE = 'a';  
        char st = en.toCharArray()[0];
        if(Character.isUpperCase(st)){
            if(en.equals("Z")){
                return "A";
            }
            if(en==null || en.equals("")){ 
                return "A";  
            }
            lastE = 'Z';  
        }else{
            if(en.equals("z")){
                return "a";
            }
            if(en==null || en.equals("")){ 
                return "a";  
            }
            lastE = 'z';  
        }
        int lastEnglish = (int)lastE;      
        char[] c = en.toCharArray();  
        if(c.length>1){  
            return null;  
        }else{  
            int now = (int)c[0];  
            if(now >= lastEnglish)  
                return null;  
            char uppercase = (char)(now+1);  
            return String.valueOf(uppercase);  
        }  
    }