본문 바로가기
Study/Java

[Java] 유용한 라이브러리

by 오늘만 사는 여자 2021. 12. 14.
728x90
반응형

StringUtils - 문자열에 작업하는 관련기능들을 모아놓은 Library

 

사용 방법

1. 직접 다운 : 다운로드페이지(Click)

 

Lang – Download Apache Commons Lang

Download Apache Commons Lang Using a Mirror We recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hour

commons.apache.org

2. Maven : MavenRepository 페이지(Click)

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.8</version>
</dependency>

직접 다운로드할 시 lib에 추가하여 사용, maven 사용시엔 pom.xml에 추가한다.

 

StringUtils.abbreviate(문자열, 보여줄 숫자(...포함))

문자열 축소하기 뒤에 숫자는 4보다 커야한다.

긴글을 정해진 글자만큼만 보여주고 ...으로 요약한다고 생각하면된다.

String abbreviate = StringUtils.abbreviate("ShowMeTheMoney", 7);
System.out.println(abbreviate);
//출력 Show...

 

StringUtils.appendIfMissing(문자열, 추가할단어, 마지막단어)

마짐가 단어가 다를 경우 추가할 단어를 추가해준다.(대소문자를 구분한다.)

String s2 = StringUtils.appendIfMissing("ShowMeTheMoney", "-From.Lee", "Money");
System.out.println(s2);
//출력 ShowMeTheMoney

s2 = StringUtils.appendIfMissing("ShowMeTheMoney",  "-From.Lee", "test");
System.out.println(s2);
//출력 ShowMeTheMoney-From.Lee

StringUtils.appendIfMissingIgnoreCase(문자열, "추가할 단어", "마지막단어")

StringUtils.appendIfMissing와 같으나 대소문자를 구분하지 않는다.

String s3 = StringUtils.appendIfMissingIgnoreCase("ShowMeTheMoney",  "-From.Lee", "money");
System.out.println(s3);
//출력 ShowMeTheMoney

 

StringUtils.capitalize(문자열)

첫글자를 대문자로 변환한다.

String s4 = StringUtils.capitalize("sss");
System.out.println(s4);

//출력 Sss

StringUtils.chomp(문자열, 제거할 문자);

마지막에 제거할 문자가 있을 경우 제거한다.

String s5 = StringUtils.chomp("sssss#", "#");
System.out.println(s5);

//출력 sssss

StringUtils.chop(문자열);

마지막 문자 하나를 제거한다.

String s6 = StringUtils.chop("ssssssddd");
System.out.println(s6);

//출력 ssssssdd

StringUtils.center(문자열, 글자수);

문자열에 설정한 글자수만큼 공백을 추가한다.

오른쪽, 왼쪽 순으로 추가된다.

String s7 = StringUtils.center("sss", 12);
System.out.println(s7);

//출력     sss     

 

출처 : https://bigstupid.tistory.com/40

728x90
반응형

댓글