이 기사에서는 상류 및 소문자로 알파벳 순서로 정렬하는 Java 구현 방법에 대해 설명합니다. 다음과 같이 참조에 대해 공유하십시오.
여기에 정렬 할 때 결과는 알파벳 순서로 얻어야합니다. 예 : a ----- z ...
import java.util.*;/*** 대문자 및 소문자 종류* @author 관리자**/public class z {// 위의 위의 것은 대문자와 후자의 정적 맵 <문자, float> map = new hashmap <문자, float> (); // HASHMAP <캐릭터 <캐릭터로 정렬 할 수 있습니다. hashmap <문자, float> (); // hashmap은 null 값을 허용 // static {문자 ch; for (ch = 65; ch <91; ch ++) {// 대문자 65.0; 66.0; 67.0; 68.0 map.put (ch, (float) ch.hashcode ()); } for (ch = 97; ch <123; ch ++) {// 소문자 64.5; 65.5 map.put (ch, (float) ch.hashcode ()-(float) 32-0.5f); } for (ch = 65; ch <91; ch ++) {// 대문자 65.0; 66.0; 67.0; 68.0 map.put (ch, (float) ch.hashcode ()); } for (ch = 97; ch <123; ch ++) {// 소문자 64.5; 65.5 map.put (ch, (float) ch.hashcode ()-(float) 32+0.5f); }} / *** @first 자본화 후 배열 값은 값 값의 값에서 맵에서 찾을 수 있습니다* @second 컬렉션 목록의 분류 방법을 통해 char 값을 얻으려면 맵의 배열* / public list addlist (char [] ar) {new Java.util.); for (int i = 0; i <ar.length; i ++) {list.add (map.get (ar [i])); } list lis = new ArrayList (); collections.sort (목록); iterator it = list.iterator (); while (it.hasnext ()) {string str = it.next (). toString (); if (str.endswith ( ". 0")) {lis.add ((char) float.parsefloat (str)); } else {lis.add ((char) (float.parsefloat (str)+0.5+32)); }} 리턴리스; } / ** * 이전 자본의 배열 값은 맵에서 찾을 수 있습니다. for (int i = 0; i <ar.length; i ++) {list.add (map.get (ar [i])); } list lis = new ArrayList (); iterator it = list.iterator (); while (it.hasnext ()) {string str = it.next (). toString (); if (str.endswith ( ". 0")) {lis.add ((char) float.parsefloat (str)); } else {lis.add ((char) (float.parsefloat (str)+0.5-32)); }} 리턴리스; } public static void main (String [] args) {System.out.println ( "wulin.com 테스트 결과 :"); char ch [] = { 'a', 'a', 'b', 'f', 'm', 'k'}; 목록 목록 = new z (). addList (ch); iterator it = list.iterator (); while (it.hasnext ()) {system.out.println (it.next ()+","); }}}실행 결과 :
Java 알고리즘에 대한 자세한 내용은이 사이트에 관심이있는 독자들이 주제를 볼 수 있습니다. "Java 데이터 구조 및 알고리즘 자습서", "Java Operation Dom Node Tips 요약", "Java 파일 및 디렉토리 작동 팁 요약"및 "Java Cache Operation Tips의 요약"을 볼 수 있습니다.
이 기사가 모든 사람의 Java 프로그래밍에 도움이되기를 바랍니다.