草庐IT

RandomStringGenerator

全部标签

java - 用于生成字母数字字符串的 RandomStringGenerator

我可以使用Apache的common-textRandomStringGenerator生成随机字母数字字符串(数字和小写/大写字母)? 最佳答案 是的,使用以下代码:importstaticorg.apache.commons.text.CharacterPredicates.DIGITS;importstaticorg.apache.commons.text.CharacterPredicates.LETTERS;//...RandomStringGeneratorgenerator=newRandomStringGenerat

java - 寻找 RandomStringUtils 的简洁替代品

Thisquestionisobsolete.org.apache.commons:commmons-lang3:3.7removedthedeprecatedflag,and3.8confirmedthat.从3.5更新到org.apache.commons:commons-lang3:3.6后,我收到许多关于RandomStringUtils被弃用的警告。建议的替代方案是commons-text中的RandomStringGenerator。但是,如果您只需要一个字符串(例如,在单元测试中),那么使用该类会非常笨拙。比较:Stringname1=RandomStringUtils.