- toString 生成
ToStringBuilder、ToStringStyle:快速產生物件的字串表示,支援多種輸出風格。- hashCode 實作
HashCodeBuilder:傳入奇數與質數參數,自動產生高品質雜湊碼。- equals 比較
EqualsBuilder:建議使用能唯一識別物件的欄位進行比較。- compareTo 排序
CompareToBuilder:參數比較順序類似堆疊,後加入的優先比較。
- 列印陣列
ArrayUtils.toString(array)、ArrayUtils.toString(list.toArray())- 複製與反轉
ArrayUtils.clone(array)、ArrayUtils.reverse(array);JDK 原生clone()也可複製陣列,Collections.reverse()可反轉 List。- 基本型別與包裝型別轉換
ArrayUtils.toObject(array)、ArrayUtils.toPrimitive(array);搭配Arrays.asList()與List.toArray()使用更靈活。- 元素查找
ArrayUtils.contains(array, value)、ArrayUtils.indexOf(array, value)、ArrayUtils.lastIndexOf(array, value)- 二維陣列轉 Map
ArrayUtils.toMap(array)
- DateFormatUtils(線程安全)
- 基於
FastDateFormat實作,適用於多執行緒環境。- 日期四捨五入
DateUtils.round(date, Calendar.**):取最接近指定欄位的日期。- 日期截斷
DateUtils.truncate(date, Calendar.**):將日期截斷到指定精度。
IdentifierUtils、IdentifierFactory:先透過IdentifierUtils取得 Factory,再產生唯一標識。
- 空值檢查:
StringUtils.isBlank()、isNotBlank()- 截斷縮寫:
StringUtils.abbreviate()- 分割字串:
StringUtils.split()- 取得夾層內容:
StringUtils.substringBetween(str, start, end)- 去除空白:
trim()、trimToNull()- 移除換行:
StringUtils.chomp()- 字串填充、置中、連接:
repeat()、center()、join()- 反轉字串:
reverse()、reverseDelimited()- 自動換行:
WordUtils.wrap()、wrapTest()- 內容測試:
isNumeric()、isAlpha()、isAlphanumeric()等- 計算出現次數:
countMatches()- 解析格式化字串:
substringBetween()、substringAfter()、substringBefore()等- 編輯距離:
getLevenshteinDistance()、difference()、indexOfDifference()
Base64、Hex、SoundEx
- 簡單屬性存取:
PropertyUtils.getSimpleProperty()- 巢狀屬性存取:
PropertyUtils.getNestedProperty()- 索引屬性存取:
PropertyUtils.getIndexedProperty()- Map 屬性存取:
PropertyUtils.getMappedProperty()- 綜合路徑存取:
PropertyUtils.getProperty(obj, "regions[0].cities(richmond).population")- 屬性類型檢查:
PropertyUtils.getPropertyType()、PropertyDescriptor相關方法- Bean 比較器:
BeanComparator- 屬性複製:
PropertyUtils.copyProperties()- Bean 複製:
BeanUtils.cloneBean()- 屬性設值:
PropertyUtils.setProperty()- 可讀/可寫判斷:
PropertyUtils.isReadable()、isWritable()- Predicate 過濾:
BeanPredicate- 轉 Map:
PropertyUtils.describe()、BeanMap- 字串化屬性:
BeanUtils.getProperty()、setProperty()
- 迭代器:
LoopingIterator、ArrayListIterator- Predicate 過濾:
FilterIterator、CollectionUtils.filter()(修改原集合)、select()/selectRejected()(回傳新集合)- 去重:
UniqueFilterIterator- 計數容器:
Bag、HashBag、TreeBag- 緩衝區:
Buffer、UnboundedFifoBuffer、BoundedFifoBuffer- 優先佇列:
PriorityBuffer- 阻塞緩衝:
BlockingBuffer.decorate()- 多值 Map:
MultiMap- 雙向 Map:
BidiMap、DualHashBidiMap、TreeBidiMap- 忽略大小寫 Map:
CaseInsensitiveMap- 型別安全集合:
TypedCollection.decorate()、TypedMap.decorate()- Predicate 限制:
PredicatedMap、PredicatedList等裝飾器- Transformer 轉換:
CollectionUtils.transform()、ChainedTransformer- LRU 快取:
LRUMap- 延遲載入 Map:
LazyMap.decorate()- 統計元素頻率:
CollectionUtils.countMatches()、cardinality()、getCardinalityMap()- 集合運算:
union()、intersection()、disjunction()、subtract()- Map 直接取值:
MapUtils.getBoolean()、getNumber()等
Digester:規則驅動的 XML 物件映射。
- 命令列解析:
CommandLineParser、Option、HelpFormatter等- 設定檔解析:
Configuration、PropertiesConfiguration、DOMConfiguration- 複合設定:
ConfigurationFactory
- 分數:
Fraction- 極值:
NumberUtils.max()、Max.evaluate()、Min.evaluate()- 數值範圍:
IntRange、DoubleRange等- 隨機數:
RandomUtils.nextInt()、nextLong()、nextBoolean()- 統計分析:
StatUtils(最大、最小、平均、總和、內積等)- 線性方程:
RealMatrix- 複數:
Complex、ComplexFormat- 迴歸分析:
SimpleRegression
commons-jexl套件
- 串流複製:
IOUtils.copy()、IOUtils.toString()- 靜默關閉:
IOUtils.closeQuietly()- 人性化檔案大小:
FileUtils.byteCountToDisplaySize()- 檔案操作:
copyFile()、writeStringToFile()、copyURLToFile()- 目錄刪除:
deleteDirectory()、cleanDirectory()- 目錄大小:
sizeOfDirectory()- 建立空檔:
FileUtils.touch()- 檔案過濾:
FilenameFilter、SuffixFileFilter、AndFileFilter等- 計數串流:
CountingInputStream、CountingOutputStream- Tee 輸出:
TeeOutputStream- Glob/Regex 過濾:
GlobFilenameFilter、Perl5FilenameFilter- 網路協議:
FTPClient、SMTPClient、POP3Client
- GET 請求範例:使用
HttpClient、GetMethod、狀態碼檢查、回應體取得、連線釋放。- 參數設定:
setQueryString()、NameValuePair- 除錯記錄:設定
org.apache.commons.logging系統屬性啟用 Wire 級別除錯。- POST 請求:
PostMethod、addParameter()- 檔案上傳:
MultipartPostMethod、addPart()- 認證機制:
HttpState(Basic)、NTCredentials(NTLM)- Cookie 處理:
Cookie類別- 重導向:
setFollowRedirects(true)- SSL 支援:
GetMethod自動處理、ProtocolSocketFactory自訂憑證- WebDAV:
WebdavResource、lockMethod/unlockMethod
commons-jxpath、lucene相關套件