BruceEckel / OnJava8-Examples

Code Examples for the book "On Java 8"

Home Page:http://www.OnJava8.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

strings/UsingStringBuilder.java has incorrect results

AttackingDinosaur opened this issue · comments

public static String string1() {
Random random = new Random(47);
StringBuilder result = new StringBuilder("[");
for (int i = 0; i < 25; i++) {
result.append(random.nextInt(100));
result.append(",");
}
// This will lead to incorrect results
// [58,55,93,61,61,29,68,0,22,7,88,28,51,89,9,78,98,61,20,58,16,40,11,22,]
result.delete(result.length() - 2, result.length());
result.append("]");
return result.toString();
}

Hey Buddy I found🪲 have a look