반응형
개발하다 보면 알파벳 포함한 문자열을 KEY로 잡으면서 시퀀셜하게 증가 시켜야하는 경우가 있습니다.
이럴 때 사용할 수 있는 알파벳 증가 시키키 함수 입니다.
아래 함수를 쓰시면 됩니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public static String nextAlphabet(String source) { int length = source.length(); char lastChar = source.charAt(length - 1); if (lastChar == 'Z') { if (length == 1) { return source = "AA"; } source = nextAlphabet(source.substring(0, length - 1)); source += "A"; return source; } return source.substring(0, length - 1) + String.valueOf((char) (lastChar + 1)); } public static void main(String[] args) { String source = "A"; for (int i = 1; i < 1000; i++) { if (i % 26 == 0) { System.out.println(); } source = nextAlphabet(source); System.out.print(source + ","); } } | cs |
결과 화면은 아래와 같습니다.
Z까지 되면 자릿수가 늘어 납니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z, AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ, BA,BB,BC,BD,BE,BF,BG,BH,BI,BJ,BK,BL,BM,BN,BO,BP,BQ,BR,BS,BT,BU,BV,BW,BX,BY,BZ, CA,CB,CC,CD,CE,CF,CG,CH,CI,CJ,CK,CL,CM,CN,CO,CP,CQ,CR,CS,CT,CU,CV,CW,CX,CY,CZ, DA,DB,DC,DD,DE,DF,DG,DH,DI,DJ,DK,DL,DM,DN,DO,DP,DQ,DR,DS,DT,DU,DV,DW,DX,DY,DZ, EA,EB,EC,ED,EE,EF,EG,EH,EI,EJ,EK,EL,EM,EN,EO,EP,EQ,ER,ES,ET,EU,EV,EW,EX,EY,EZ, FA,FB,FC,FD,FE,FF,FG,FH,FI,FJ,FK,FL,FM,FN,FO,FP,FQ,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N,ADO,ADP,ADQ,ADR,ADS,ADT,ADU,ADV,ADW,ADX,ADY,ADZ, AEA,AEB,AEC,AED,AEE,AEF,AEG,AEH,AEI,AEJ,AEK,AEL,AEM,AEN,AEO,AEP,AEQ,AER,AES,AET,AEU,AEV,AEW,AEX,AEY,AEZ, AFA,AFB,AFC,AFD,AFE,AFF,AFG,AFH,AFI,AFJ,AFK,AFL,AFM,AFN,AFO,AFP,AFQ,AFR,AFS,AFT,AFU,AFV,AFW,AFX,AFY,AFZ, AGA,AGB,AGC,AGD,AGE,AGF,AGG,AGH,AGI,AGJ,AGK,AGL,AGM,AGN,AGO,AGP,AGQ,AGR,AGS,AGT,AGU,AGV,AGW,AGX,AGY,AGZ, AHA,AHB,AHC,AHD,AHE,AHF,AHG,AHH,AHI,AHJ,AHK,AHL,AHM,AHN,AHO,AHP,AHQ,AHR,AHS,AHT,AHU,AHV,AHW,AHX,AHY,AHZ, AIA,AIB,AIC,AID,AIE,AIF,AIG,AIH,AII,AIJ,AIK,AIL,AIM,AIN,AIO,AIP,AIQ,AIR,AIS,AIT,AIU,AIV,AIW,AIX,AIY,AIZ, AJA,AJB,AJC,AJD,AJE,AJF,AJG,AJH,AJI,AJJ,AJK,AJL,AJM,AJN,AJO,AJP,AJQ,AJR,AJS,AJT,AJU,AJV,AJW,AJX,AJY,AJZ, AKA,AKB,AKC,AKD,AKE,AKF,AKG,AKH,AKI,AKJ,AKK,AKL,AKM,AKN,AKO,AKP,AKQ,AKR,AKS,AKT,AKU,AKV,AKW,AKX,AKY,AKZ, ALA,ALB,ALC,ALD,ALE,ALF,ALG,ALH,ALI,ALJ,ALK,ALL, | cs |
반응형
'java' 카테고리의 다른 글
java domain to ip address (0) | 2017.11.13 |
---|---|
org/springframework/boot/logging/logback/base.xml (0) | 2017.11.06 |
java - replace All 대소문자 ignore case (0) | 2017.10.26 |
java - 한글 이름 랜덤 생성 (6) | 2017.10.25 |
spring secuirty - how to catch CookieTheftException (0) | 2017.10.16 |
java - outbound 포트 방화벽 확인을 위한 port listen 소스 (1) | 2017.09.26 |
spring boot - @Scheduled Test (2) | 2017.09.19 |
netty - IoBuffer vs ChannelBuffer (0) | 2017.09.18 |