java random string fixed length code example
Example: java 8 random string generator
@Test
public void givenUsingJava8_whenGeneratingRandomAlphanumericString_thenCorrect() {
int leftLimit = 48;
int rightLimit = 122;
int targetStringLength = 10;
Random random = new Random();
String generatedString = random.ints(leftLimit, rightLimit + 1)
.filter(i -> (i <= 57 || i >= 65) && (i <= 90 || i >= 97))
.limit(targetStringLength)
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
System.out.println(generatedString);
}