string s=”113545asadf5555vnm.hk#&&1158ghs “

string s=”113545asadf5555vnm.hk#&&1158ghs “如何分别对数字字母进行排序

public static void mainString[] args { String s = "113545asadf5555vnm.hk#&&1158ghs "; System.out.printlnsortNums; System.out.printlnsortAlphabets;
} private static String sortNumString s { char c; List<Character> numList = new ArrayList<Character>; for int i = 0; i < s.length; i++ { c = s.charAti; if 0 <= c && c <= 9 { numList.addc; } } Collections.sortnumList; StringBuilder sb = new StringBuilder; for Character character : numList { sb.appendcharacter; } return sb.toString;
} private static String sortAlphabetString s { char c; List<Character> alphabetList = new ArrayList<Character>; for int i = 0; i < s.length; i++ { c = s.charAti; if a <= c && c <= z || A <= c && c <= Z { alphabetList.addc; } } Collections.sortalphabetList; StringBuilder sb = new StringBuilder; for Character character : alphabetList { sb.appendcharacter; } return sb.toString;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注