RandomStringUtils

xiaoxiao2025-09-14  270

目录

【Maven依赖】【常用 API】


【Maven依赖】

本文以3.7版本为例:

<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.7</version> </dependency>

【常用 API】

【生成指定长度, 数字随机组合字符串】

RandomStringUtils.randomNumeric(int count);

【生成指定长度, [a-zA-Z]大小写字母随机组合字符串】

RandomStringUtils.randomAlphabetic(int count);

【生成指定长度, 字母和数字随机组合字符串】

RandomStringUtils.randomAlphanumeric(int count);

【生成指定长度, 由指定字符随机组合字符串】

RandomStringUtils.random(int count, String str); // 例:生成5位由"abcdefghijklmnopqrstuvwxyz0123456789"组成的随机字符串,如"56abd2" RandomStringUtils.random(5, "abcdefghijklmnopqrstuvwxyz0123456789");
转载请注明原文地址: https://www.6miu.com/read-5036321.html

最新回复(0)