๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“– Java&Spring

StringUtils

StringUtils

๐Ÿ“•API ๋ฌธ์„œ

StringUtils๋Š” ๋ฌธ์ž์—ด์„ ๊ฒ€์‚ฌํ•  ๋•Œ๋‚˜ ๋ณ€ํ™˜ํ•  ๋•Œ ์œ ์šฉํ•˜๊ฒŒ ์“ฐ์ด๋Š” ํด๋ž˜์Šค ์ž…๋‹ˆ๋‹ค

1) Class

  • java.lang.Object
  • org.apache.commons.lang3.StringUtils2) ํŠน์ง•
  • NullPointException ๋ฐœ์ƒ X
  • ThreadSafe

๐ŸŒฑ String Handling

String ์ฒ˜๋ฆฌ ํด๋ž˜์Šค ๋‹ต๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋‹จ์–ด๋“ค์ด ์žˆ๋Š”๋ฐ์šฉ, ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • null: ๋ง ๊ทธ๋Œ€๋กœ null
  • empty: ๋นˆ ๋ฌธ์ž ("')
  • space: ์ŠคํŽ˜์ด์Šค ('', char ํ˜•)
  • whitespace: ์—ฌ๋ฐฑ, Character.isWhitespace(char๋ฅผ ์ฐธ๊ณ )
  • trim

๐ŸŒฑ Operations

์ด ๋•Œ ์•„๋‹ˆ๋ฉด ์–ธ์ œ ๋‹ค ์ฝ์–ด๋ณด๊ฒ ์Šต๋‹ˆ๊นŒ? ๐Ÿ˜ฅ

๐Ÿ’ก๊ธฐ๋ณธ์ ์œผ๋กœ null-safe ๋™์ž‘์„ ํ•ฉ๋‹ˆ๋‹ค.

  • IsEmpty/IsBlank
  • Trim/Strip: ์ ‘๋‘/์ ‘๋ฏธ์— ์žˆ๋Š” ๊ณต๋ฐฑ์„ ์ œ๊ฑฐ
  • Equals/Compare: ๋‘ ๊ฐœ ๋ฌธ์ž์—ด ๋น„๊ต
  • startsWith : prefix ํ™•์ธ
  • endsWith: suffix ํ™•์ธ
  • IndexOf/LastIndexOf/Contains: ๋ฌธ์ž์—ด ์ธ๋ฑ์Šค ํ™•์ธ
  • IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut: ์—ฌ๋Ÿฌ ๋ฌธ์ž์—ด์˜ ์ธ๋ฑ์Šค ํ™•์ธ
  • ContainsOnly/ContainsNone/ContainsAny: ๋ฌธ์ž์—ด์— ํŠน์ • ๋‹จ์–ด๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ
  • Substring/Left/Right/Mid: ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ์ถ”์ถœ
  • SubstringBefore/SubstringAfter/SubstringBetween: ๊ฒ€์‚ฌํ•  ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด๋ถ„๋ฆฌ๊ธฐํ˜ธ๋ฅผ ๋‘๊ณ , ์•ž/๋’ค/์‚ฌ์ด ๋ฌธ์ž๋“ค์„ ์ถ”์ถœ
  • Split/Join
  • Remove/Delete
  • Replace/Overlay
  • Chomp/Chop(์ฉ์ฉ๋ฐ•์‚ฌ): ๋งˆ์ง€๋ง‰์— ๊ฐœํ–‰๋ฌธ์ž(CRLF)๊ฐ€ ์žˆ๋‹ค๋ฉด ์ œ๊ฑฐํ•ด์คŒ
  • AppendIfMissing: ๋ฌธ์ž์—ด ๋์— suffix ์ถ”๊ฐ€ํ•ด์คŒ (์—†์„ ๊ฒฝ์šฐ์—)
  • PrependIfMissing : ๋ฌธ์ž์—ด ์•ž์— preffix ์ถ”๊ฐ€ํ•ด์คŒ (์—†์„ ๊ฒฝ์šฐ์—)
  • LeftPad/RightPad/Center/Repeat: ๋ฌธ์ž์—ด ํฌ๊ธฐ๋งŒํผ ์™ผ/์˜ค/๊ฐ€์šด๋ฐ์— ์ถ”๊ฐ€ ๋‹จ์–ด๋ฅผ ์ƒ์„ฑํ•ด์คŒ
  • UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize
  • CountMatches
  • IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable
  • DefaultString: argument๊ฐ€ null์ด๋ฉด ๋นˆ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•ด์คŒ
  • Rotate : ๋ฌธ์ž์—ด์„ ์‹œ๊ณ„/๋ฐ˜์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ ์ด๋™์‹œ์ผœ์คŒ
  • Reverse/ReverseDelimited
  • Abbreviate : ์ถ•์•ฝ ๊ธฐ๋Šฅ
  • Difference
  • LevenshteinDistance: ๋ฌธ์ž์—ด A์—์„œ ๋ฌธ์ž์—ด B๋กœ ๋ณ€๊ฒฝํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ๋ณ€๊ฒฝ ํšŸ์ˆ˜

๐ŸŒฑ Methods

API ๋ฌธ์„œ ์ฐธ๊ณ 

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html