No, not like this:
String stringName = "example";
String stringName2 = ("\"" + stringName + "\" secretly means \"i like trains\"");
The code I tried to use is:
long amountOfChars = chars.length;
int amountOfTimesLeft = 20;
String out = null;
Random random = new Random();
while (amountOfTimesLeft != 0) {
long whichChar = (random.nextInt((int) (amountOfChars - 0 + 1)) + 0);
StringBuilder sb = new StringBuilder(chars[(int) whichChar]);
sb.append(out);
}
("chars" is an array of strings I've already defined)
What I expected it to do is: Get a random string from the chars array and add it to the out string, and repeat it 19 more times.
What it does:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 32 out of bounds for length 32
at Main.main(Main.java:45)
I have really no idea what this means. Could someone help? (line 45 is the line that defines sb)
And yes, I know I forgot to decrease amountOfTimesLeft, but that's not the point of this question.